Class static variables
Niels Diepeveen
niels at endea.demon.nl
Fri Jul 21 06:52:56 EDT 2000
desnoix at my-deja.com schreef:
>
> I'm writing a tool to translate a variety of OO
> programming languages. Especially I target Python
> but I am hesitating about the way to define
> class-scope static variables. Could you suggest me
> what is the best and natural form ?
>
> Example: MyClass { static int a; }
> - MyClass_a
> - accessors + global var
> - any other form
MyClass.a will work unless it is a function. (class attributes that are
functions are magically turned into instance methods) For example:
class MyClass:
#define class attribute
a = 0
def method(self):
#use class attribute
do_something_with(MyClass.a)
#use class attribute outside of MyClass
do_something_else_with(MyClass.a)
--
Niels Diepeveen
Endea automatisering
More information about the Python-list
mailing list