python Programming Glossary: self.fn
Safe way to parse user-supplied mathematical formula in Python http://stackoverflow.com/questions/11951701/safe-way-to-parse-user-supplied-mathematical-formula-in-python operator.mul operator.truediv ^ operator.pow self.fn sin math.sin cos math.cos tan math.tan abs abs trunc lambda.. elif op E return math.e # 2.718281828 elif op in self.fn return self.fn op self.evaluateStack s elif op 0 .isalpha return.. op E return math.e # 2.718281828 elif op in self.fn return self.fn op self.evaluateStack s elif op 0 .isalpha return 0 else return..
allow users to “extend” API functions http://stackoverflow.com/questions/14174799/allow-users-to-extend-api-functions hookable object def __init__ self fn self.pre self.post self.fn fn def add_pre self hook self.pre.append hook def add_post self.. self args kwargs for hook in self.pre hook args kwargs ret self.fn args kwargs for hook in self.post hook args kwargs return ret..
How to update image in tkinter label? http://stackoverflow.com/questions/14291434/how-to-update-image-in-tkinter-label row 1 column 2 def setImage self self.img Image.open self.fn self.I numpy.asarray self.img l h self.img.size text str 2 l.. tkFileDialog.Open self filetypes ftypes filename dlg.show self.fn filename #print self.fn #prints filename with path here self.setImage.. filetypes ftypes filename dlg.show self.fn filename #print self.fn #prints filename with path here self.setImage #def onError self..
Pickling a staticmethod in Python http://stackoverflow.com/questions/1914261/pickling-a-staticmethod-in-python object def __init__ self fn cls None self.cls cls self.fn fn def __call__ self args kwargs return self.fn args kwargs.. cls self.fn fn def __call__ self args kwargs return self.fn args kwargs def __get__ self obj cls return PickleableStaticMethod.. def __get__ self obj cls return PickleableStaticMethod self.fn cls def __getstate__ self return self.cls self.fn.__name__ def..
Evaluating a mathematical expression in a string http://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string operator.mul operator.truediv ^ operator.pow self.fn sin math.sin cos math.cos tan math.tan abs abs trunc lambda.. elif op E return math.e # 2.718281828 elif op in self.fn return self.fn op self.evaluateStack s elif op 0 .isalpha return.. op E return math.e # 2.718281828 elif op in self.fn return self.fn op self.evaluateStack s elif op 0 .isalpha return 0 else return..
Python - anyone have a memoizing decorator that can handle unhashable arguments? http://stackoverflow.com/questions/4669391/python-anyone-have-a-memoizing-decorator-that-can-handle-unhashable-arguments import cPickle class MemoizeMutable def __init__ self fn self.fn fn self.memo def __call__ self args kwds import cPickle str.. str print miss # DEBUG INFO self.memo str self.fn args kwds else print hit # DEBUG INFO return self.memo str Here..
Python Class Based Decorator with parameters that can decorate a method or a function http://stackoverflow.com/questions/9416947/python-class-based-decorator-with-parameters-that-can-decorate-a-method-or-a-fun class MyDecorator object def __init__ self fn argument self.fn fn self.arg argument def __get__ self .... # voodoo magic for.. print In my decorator before call with arg s self.arg self.fn args kwargs print In my decorator after call with arg s self.arg..
|