questions about scope/threading
Aahz
aahz at pythoncraft.com
Fri Nov 15 00:06:23 EST 2002
In article <ar1tph$q7$1 at wheel2.two14.net>, <maney at pobox.com> wrote:
>Aahz <aahz at pythoncraft.com> wrote:
>>
>> 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.
>
>I hadn't thought about Python's scoping that way before. So anything not
>"hidden" inside a function is present in the global tree of namespaces?
>(or class definition. hmmm, any others?)
<evil grin> No, *everything* is global. Here's a fun one:
import dis
def f():
print "Hello, world!"
print dir(f)
print dir(f.func_code)
print "Python bytecode for f:", repr(f.func_code.co_code)
print
print "Disassembled bytecode for f:"
print dis.dis(f)
One way or another, every object in Python is reachable using Python
code. See also the gc module.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
A: No.
Q: Is top-posting okay?
More information about the Python-list
mailing list