package/namespace confusion

Ben Hutchings ben.hutchings at
Tue Mar 6 23:34:27 CET 2001

Bruce Edge <bedge at> writes:

> Hi,
> I'm sure this is a real rookie issue here, but I can't seem to define a
> global then access it in a package.
> I'm using to define glob_var, then load
> I would have expected util/ufunc() to have access to glob_var.
> test/
> glob_var=0        <- is this where I should stick package globals?


> __all__=["util"]
> test/
> def ufunc():
> 	global glob_var

The global namespace for this function is the namespace of the module
(test.util) not that of the package (test).

If you want package globals to be module globals too, then use
'from test import *' at the top of your modules.  Alternatively you
can 'import test' and refer to 'test.glob_var'.

Any opinions expressed are my own and not necessarily those of Roundpoint.

More information about the Python-list mailing list