How to store a function pointer in class?
Sami Hangaslammi
shang.remove_edu at st.jyu.fi.edu
Thu Jan 20 13:12:27 EST 2000
Consider the follwing example:
>>> sys.version
'1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)]'
>>> class Test:
class_attribute = None
>>> def test_func(x):
print "test_func called with",x
>>> test_func
<function test_func at b4e620>
>>> Test.class_attribute = test_func
>>> Test.class_attribute
<unbound method Test.test_func>
>>> Test.__dict__['class_attribute']
<function test_func at b4e620>
Now I have a script where I need to store pointers to functions (among
other things) to class attributes and retrieve them as ordinary
functions. How do I do this (besides that VERY ugly syntax above)?
--
Sami Hangaslammi
shang (at) st (dot) jyu (dot) fi
More information about the Python-list
mailing list