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 ?
This is what decorators are for. This decorator, used on
foowithbaras an argument will will runbarafterfooand still returnfoos result. It will work on functions with any number of arguments.Edit: Added error handling. Thanks @Björn