Re: Why there is a parameter named self for classmethod function?

2009-05-11 Thread Bruno Desthuilliers
Terry Reedy a écrit : Kurt Symanzik wrote: But you might consider decorating the method as a static method instead since in your example you are not using the parameter at all. A static method would not require a parameter. @staticmethod def print_hello(): print hello Functions

Re: Why there is a parameter named self for classmethod function?

2009-05-09 Thread Aaron Brady
On May 8, 7:52 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Thu, 07 May 2009 04:27:15 -0700, Aaron Brady wrote: Can be, but if there's reason enough to keep it with a class, there's no reason not to. That's a bit of hyperbole; the usual reasons such as code bloat,

Re: Why there is a parameter named self for classmethod function?

2009-05-08 Thread Steven D'Aprano
On Thu, 07 May 2009 04:27:15 -0700, Aaron Brady wrote: Can be, but if there's reason enough to keep it with a class, there's no reason not to. That's a bit of hyperbole; the usual reasons such as code bloat, namespace bloat, maintainability etc. all weigh against it. It's just that the

Re: Why there is a parameter named self for classmethod function?

2009-05-07 Thread Steven D'Aprano
On Thu, 07 May 2009 00:39:28 -0400, Terry Reedy wrote: Functions that refer to neither the class nor an instance thereof can usually be moved outside the class altogether. Python is not Java. I believe staticmethod() was mainly added because it is needed for .__new__(), at least in some

Re: Why there is a parameter named self for classmethod function?

2009-05-07 Thread Aaron Brady
On May 7, 1:29 am, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Thu, 07 May 2009 00:39:28 -0400, Terry Reedy wrote: Functions that refer to neither the class nor an instance thereof can usually be moved outside the class altogether.  Python is not Java.  I believe

Why there is a parameter named self for classmethod function?

2009-05-06 Thread Jianchun Zhou
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

Re: Why there is a parameter named self for classmethod function?

2009-05-06 Thread Chris Rebert
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

Re: Why there is a parameter named self for classmethod function?

2009-05-06 Thread Kurt Symanzik
Jianchun Zhou jianchun.z...@gmail.com wrote on 2009-05-07 10:49:33 AM +0800 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

Re: Why there is a parameter named self for classmethod function?

2009-05-06 Thread Terry Reedy
Kurt Symanzik wrote: But you might consider decorating the method as a static method instead since in your example you are not using the parameter at all. A static method would not require a parameter. @staticmethod def print_hello(): print hello Functions that refer to neither the