Class variables / global variables / Init variables
Mikael Olofsson
mikael at isy.liu.se
Mon May 15 11:37:57 EDT 2000
On 15-May-00 abouf066 at aix2.uottawa.ca wrote:
> class myClass :
> myVariable = 10
> def __init__(self):
> global myVariable
> newWindow = myWindow(myVariable)
This should not work at all, unless you have a global myVariable,
i.e. outside myClass.
If you want myVariable to be shared between all instances of myClass,
then I think you want this:
class myClass :
myVariable = 10
def __init__(self):
newWindow = myWindow(myClass.myVariable)
If instead you want each instance of myClass to have its own myVariable,
then I think you want this:
class myClass :
def __init__(self):
self.myVariable = 10
newWindow = myWindow(self.myVariable)
Then again, I could have completely misunderstood you.
/Mikael
-----------------------------------------------------------------------
E-Mail: Mikael Olofsson <mikael at isy.liu.se>
WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date: 15-May-00
Time: 17:27:46
This message was sent by XF-Mail.
-----------------------------------------------------------------------
More information about the Python-list
mailing list