questions about scope/threading
Aahz
aahz at pythoncraft.com
Thu Nov 14 15:46:18 EST 2002
In article <aokrjb$eaj$1 at newsreader.mailgate.org>,
eugene kim <eugene1977 at hotmail.com> wrote:
>Aahz:
>>
>>The trick with Python is that ALL objects are truly global
> ?? i 'm really confused, what is refered as global? i thought 'var1' is
>only global here on below example.
Python uses "global" to mean "module scope". There's also the common
meaning, which is "accessible everywhere"; that's the meaning I'm using
for "truly global".
>var1 = 1
>
>class Class1:
> self.var2 = 2
> var3 = 3
>
>class Class2(threading.Thread)
> self.var4 = 4
> var5 = 5
> def method1(self):
> var6 = 6
Thing is, while var3 is not a module global, any thread can access that
name through Class1.var3 -- therefore, the object bound to Class1.var3
is a completely global object, and you have to be careful what you do
with Class1.var3 (or the object bound to it if the object is mutable).
Tricky stuff.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
A: No.
Q: Is top-posting okay?
More information about the Python-list
mailing list