sharing vars with different functions

Martin Marcher martin at marcher.name
Mon Oct 29 05:56:45 EDT 2007


I hate gmail, always forgetting to set the right recipient...


---------- Forwarded message ----------
From: Martin Marcher <martin at marcher.name>
Date: 29.10.2007 10:11
Subject: Re: sharing vars with different functions
To: "scripteaze at gmail.com" <scripteaze at gmail.com>


2007/10/29, scripteaze at gmail.com <scripteaze at gmail.com>:
> Im tryin to call a var thats sitting in a function, example:
>
> i  guess im not graspng the whole global or local var topic..

does this help?

>>> class Foo(object):
...     somevar = ["a", "b"]
...     def __init__(self):
...             self.another_var = ["c", "d"]
...
>>> Foo.somevar
['a', 'b']
>>> f = Foo()
>>> f.somevar
['a', 'b']
>>> f.another_var
['c', 'd']
>>> Foo.somevar = "New Value"
>>> f.somevar
'New Value'
>>> Foo.another_var
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'Foo' has no attribute 'another_var'



--
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours


-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours



More information about the Python-list mailing list