On Wed, May 6, 2009 at 7:49 PM, Jianchun Zhou <jianchun.z...@gmail.com> wrote: > Hi, ALL: > > I have a sample code as bellow: > > #!/usr/bin/env python > > class Hello: > def __init__(self): > print "Hello __init__" > @classmethod > def print_hello(self): > print "hello" > > Hello.print_hello() > > If I move "self" parameter of print_hello away, this code fragment won't > work. > > I am wondering when Hello.print_hello() executes, what value will "self" be > asigned?
The class itself will be the value of self (hence the "class" in "classmethod") in that case. For this reason, the parameter is conventionally called "cls" rather than "self", to avoid confusion. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list