Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32489
| Date | 2012-10-30 06:41 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: calling one staticmethod from another |
| References | <tit4m9-1ei.ln1@satorlaser.homedns.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3090.1351604780.27098.python-list@python.org> (permalink) |
Ulrich Eckhardt wrote:
> I can call a staticmethod f() of class C like "C.f()" or with an
> instance like "C().f()". Inside that staticmethod, I have neither the
> class (at least not the original one) nor do I have an instance, so I
> can't call a different staticmethod from the same class. The obvious
> solution is to make this a classmethod instead, with a mostly-unused
> "cls" parameter.
>
> Am I missing something?
class Spam():
@staticmethod
def green():
print('on a train!')
@staticmethod
def question():
print('would you, could you', end='')
Spam.green()
It can be a pain if you change the class name, but it is certainly one way to do it.
~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
calling one staticmethod from another Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-30 13:25 +0100
Re: calling one staticmethod from another Ethan Furman <ethan@stoneleaf.us> - 2012-10-30 06:41 -0700
Re: calling one staticmethod from another Dave Angel <d@davea.name> - 2012-10-30 09:47 -0400
Re: calling one staticmethod from another Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-30 16:39 +0100
Re: calling one staticmethod from another Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-30 09:27 -0600
Re: calling one staticmethod from another Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-30 21:29 +0000
csiph-web