Project-wide variable...
Peter Otten
__peter__ at web.de
Thu Jun 23 10:42:58 EDT 2011
Gnarlodious wrote:
> On Jun 23, 7:59 am, Noah Hall wrote:
>> >>>from a import x
>
> I'm doing that:
> import Module.Data as Data
from Module import Data
There, you saved three more characters .
> However I end up doing it in every submodule, so it seems a little
> redundant. I wish I could load the variable in the parent program and
> have it be available in all submodules. Am I missing something?
You can modify the builtin namespace:
$ cat module.py
print data
$ cat main.py
import __builtin__
__builtin__.data = 42
import module
$ python main.py
42
$
But I don't think it's a good idea. Remember that "explicit is better than
implicit".
More information about the Python-list
mailing list