[C++-sig] RE: static methods

Paul F Dubois paul at pfdubois.com
Sun Jan 12 07:55:34 CET 2003


I found it hard to read the thread due to html embedded in my digest, but
one thing I did notice was that in Python you did not have your class C
inherit from object. If you use property, staticmethod, or classmethod in an
old-style class, they work but they don't work, if you get my drift. They
execute at class compile time but don't function properly.
Here is a correct example. I hope this is the source of your difficulty.

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> class C (object):
	def f(x,y):
		return x + y
	f = staticmethod(f)

	
>>> C.f(3,2)
5
>>> c=C()
>>> c.f(3,2)
5

Note that the call to staticmethod is at the same level of indentation as
the def f. This happens during class definition. 

Moral: metaclasses make your head explode.





More information about the Cplusplus-sig mailing list