Unexpected python exception

Andreas Löscher andreas.loescher at s2005.tu-chemnitz.de
Wed Nov 11 07:23:30 EST 2009


Python searches for Variables not only in local or global scoop but also
in __builtins__. If you do something like __builtins__.os = os, than
this variable should be accessible global. 

If you then write something like:
def B():
	os.stat("/")
	import os

Python recognises on compile time, that os is a local variable in B and
allocates memory for it. All reading or writing now goes to the local
variable and not the one in __builtins__. And the local variable has
never been assigned to a value and an Exception is thrown.

Best




More information about the Python-list mailing list