Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6240529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:35:11+00:00 2026-05-24T11:35:11+00:00

def foo(): pass def bar(): print ‘good bay’ two function like blow and now

  • 0
def foo():
    pass

def bar():
    print 'good bay'

two function like blow
and now i want to run bar function after foo run finish

is there some method like class use __del__?
as i know in class method i can use __del__ like follow:

 class A(object):
    def __init__(self):
        pass
    def __del__(self):
        bar()

but i can’t use foo.__del__
is there any other method to do this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:35:13+00:00Added an answer on May 24, 2026 at 11:35 am

    This is what decorators are for. This decorator, used on foo with bar as an argument will will run bar after foo and still return foos result. It will work on functions with any number of arguments.

    def run_before(lastfunc, *args1, **kwargs1):
        def run(func):
            def wrapped_func(*args, **kwargs):
                try:
                    result = func(*args, **kwargs)
                except:
                    result = None
                finally:
                    lastfunc(*args1, **kwargs1)
                    return result
            return wrapped_func
        return run
    
    def bar():
        print 'goodby'
    
    @run_before(bar)
    def foo():
        print "hello"
    
    foo()
    

    Edit: Added error handling. Thanks @Björn

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I added a get_absolute_url function to one of my models. def get_absolute_url(self): return '/foo/bar'
foo = foo def bar(foo): foo = bar bar(foo) print foo # foo is
What do *args and **kwargs mean in these function definitions? def foo(x, y, *args):
my ruby (on rails) class looks like: class Foo def self.method1 someAction end def
class Ball: a = [] def __init__(self): pass def add(self,thing): self.a.append(thing) def size(self): print
I have a Python module with a function in it: == bar.py == def
Here's an example of my problem : class bar() : spam = foo() def
def foo (): x = re.compile('^abc') foo2(x) def foo2(x): How do I get x
Using Scala's command line REPL: def foo(x: Int): Unit = {} def foo(x: String):
I have a class: class MyClass: def __init__(self, foo): if foo != 1: raise

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.