Thomas Heller wrote: >=20 > From: "M.-A. Lemburg" <mal@lemburg.com> > > AFAIK, the only way to add classmethods to a class is by doing > > so after creation of the class object. > Wrong IMO: >=20 > 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 =3D classmethod(foo) > ... global x > ... x =3D (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>> >=20 > The classmethod is created before the class is done, > it is converted into a method bound to the class > when you access it. Touch=E9 :-) --=20 Marc-Andre Lemburg CEO eGenix.com Software GmbH ______________________________________________________________________ Consulting & Company: http://www.egenix.com/ Python Software: http://www.lemburg.com/python/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4