a class variable question
Bruno Desthuilliers
onurb at xiludom.gro
Wed Jun 28 06:36:53 EDT 2006
micklee74 at hotmail.com wrote:
> hi
> i have define a class like this
>
# class A:
class A(object):
> _var1 = 0
> def __init__(self):
> ## some initialization
> self.func1()
>
# def func1():
def func1(self):
> .....
# _var1 = 1
self.__class__._var1 = 1
# or if func1() does'nt use any instance attributes:
# @classmethod
# def func1(cls):
# ....
# cls._var1 = 1
> def getvarValue(self):
# return _var1
return self.__class__._var1
> I wanted var1 to be "global" inside Class A.
The name is "class attribute".
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list