How to store a function pointer in class?

Sami Hangaslammi shang.remove_edu at st.jyu.fi.edu
Thu Jan 20 14:23:40 EST 2000


Justin Sheehy <dworkin at ccs.neu.edu> wrote in message
news:vndaem01s1r.fsf at betelgeuse.ccs.neu.edu...

> A class or instance variable may be a reference to a function
object, though.

If wish they could! The problem is that a class variable can NOT refer
a function object, only an unbound method object. When a reference to
a function object is stored in a class variable, it is instatly
transformed into an unbound method (or so it seems).

> Since I'm not sure what you want to _do_ with your function
pointers,
> I'm not sure if I am answering your real question.  This may be
helpful:

Sorry, I wasn't being clear enough. This is what I want to do:

>>> Test.class_attribute = some_func
>>> another_func = Test.class_attribute
>>> another_func == some_func  # here's the problem :(
0

So I wan't to store function references into class variables and
retrieve them unchanged.

--
Sami Hangaslammi
shang (at) st (dot) jyu (dot) fi





More information about the Python-list mailing list