Can __iter__ be used as a classmethod?

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Mon Mar 10 22:42:01 EST 2003


Michele Simionato wrote:
> It seems I must define a dummy class
> 
>>>>class C(object): pass
> 
> bound the classmethod to it
> 
>>>>C.c=c
> 
> and then retrieve the original function via im_func
> 
>>>>C.c.im_func
> 
> It there must be a better way!

It seems like you should be able to do
c.__get__(None).im_func. I just tried that
and I got

Python 2.2 (#1, Jul 11 2002, 14:19:37)
[GCC 3.0.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> def f(x): return x
...
>>> c=classmethod(f)
>>> d = c.__get__(None)
Segmentation fault (core dumped)

Oops! But it would probably have worked if I had a less
buggy version of Python...

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list