[Python-Dev] Re: Static method and class method comments

M.-A. Lemburg mal at lemburg.com
Thu Jul 26 06:10:36 EDT 2001


Thomas Heller wrote:
> 
> From: "M.-A. Lemburg" <mal at lemburg.com>
> > AFAIK, the only way to add classmethods to a class is by doing
> > so after creation of the class object.
> Wrong IMO:
> 
> C:\>c:\python22\python.exe
> Python 2.2a1 (#21, Jul 18 2001, 04:25:46) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> >>> class X:
> ...   def foo(*args): return args
> ...   goo = classmethod(foo)
> ...   global x
> ...   x = (foo, goo)
> ...
> >>> print x
> (<function foo at 007B786C>, <classmethod object at 007C7190>)
> >>> print X.foo, X.goo
> <unbound method X.foo> <bound method class.foo of <class __main__.X at 007B6664>>
> 
> The classmethod is created before the class is done,
> it is converted into a method bound to the class
> when you access it.

Touché :-)

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/




More information about the Python-list mailing list