Static member variables
Johannes Zellner
johannes at zellner.org
Sun Jul 9 18:29:55 EDT 2000
On Sun, 9 Jul 2000, Jerome Quelin wrote:
> "Thomas Svensson" <thomas_s at ebox.tninet.se> wrote:
> >Is there a way of declaring static (and constant) member variables in
> >classes? I have a member variable that should be unique for each class
> >type and thus should not waste memory for each instance of the class I
> >create. Something like the __doc__ string I guess.
>
> And is it possible to have a static method (ie, a class method in C++ jargon) ?
>
> >>> class t:
> .. def t():
> .. print "t.t"
> >>> t.t()
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> TypeError: unbound method must be called with class instance 1st argument
try this:
class t:
def t(self):
print "t.t"
t.t()
the `self' is always supplied for memeber functions as the first
argument. `self' is something like `this' in C++. It's the instance
itself (calling it `self' is just convention).
--
Johannes
More information about the Python-list
mailing list