python Programming Glossary: f.__name__
Preprocessing function text in runtime bofore compilation http://stackoverflow.com/questions/12238511/preprocessing-function-text-in-runtime-bofore-compilation exec new_source in env finally _blocked False return env f.__name__ @remove_1 def f 1 a print 'Some statements 1' 1 a print 'Some..
Python 3 and static typing http://stackoverflow.com/questions/1275646/python-3-and-static-typing f '__type_checked' False log 'Decorated 0 r .'.format f.__name__ d k decorate_func f if __name__ '__main__' decorate_module #..
Preserving signatures of decorated functions http://stackoverflow.com/questions/147816/preserving-signatures-of-decorated-functions v for k v in kwargs.items return f args kwargs g.__name__ f.__name__ g.__doc__ f.__doc__ return g @args_as_ints def funny_function.. f def g x y z 3 return f int x int y z int z g.__name__ f.__name__ g.__doc__ f.__doc__ return g This works fine for a set of functions..
Python: removing duplicates from a list of lists http://stackoverflow.com/questions/2213923/python-removing-duplicates-from-a-list-of-lists dogroupby donewk resk f k assert k savek print ' 10s s' f.__name__ sorted resk Note the sanity check performed when you just do..
how to measure execution time of functions (automatically) in Python http://stackoverflow.com/questions/2245161/how-to-measure-execution-time-of-functions-automatically-in-python args kwds elapsed time start print s took d time to finish f.__name__ elapsed return result return wrapper This is an example of its..
is there a self flag can reference python function inside itself? http://stackoverflow.com/questions/5063607/is-there-a-self-flag-can-reference-python-function-inside-itself then I may write code like this def whatever print self.__name__ print self.__hash__ # other simliar I searched and found someone.. wraps def showinfo f @wraps f def wrapper args kwds print f.__name__ f.__hash__ return f args kwds return wrapper @showinfo def aa.. f args kwds return wrapper @withself def aa self print self.__name__ # etc. Edit to add alternate decorator You can also write a..
|