static class methods in Python?
neelk at brick.cswv.com
Sat Feb 19 03:03:45 CET 2000
Aahz Maruch <aahz at netcom.com> wrote:
> In article <slrn8arn3d.9md.neelk at brick.cswv.com>,
> Neel Krishnaswami <neelk at alum.mit.edu> wrote:
> >This is probably a stupid question, but what /is/ a class method?
> >I've never programmed in C++ (or Java), so an explanation would be
> Class methods are used to access and modify class variables. For
> class foo:
> bar = None
> def __init__(self):
> classdef isdone():
> if foo.bar is not None:
> return "!!!"
> classdef clear():
> foo.bar = None
I'd agree that the self.__class__.bar you'd have to do in real Python
is a little bit ugly. One thing I looked at doing was changing Python
so the syntax "class.foo" would expand to "self.__class__.foo" (or
whatever "self" actually is). This would solve the problem without
adding a new keyword.
However, I was scared away by the following comment in Parser/pgen.c:
/* This algorithm is from a book written before
the invention of structured programming... */
More information about the Python-list