multiple namespaces within a single module?

Ethan Furman ethan at stoneleaf.us
Thu Feb 9 17:25:46 EST 2012


Peter Otten wrote:
> Hm, what about
> 
> with NameSpace(globals()) as a:
>     x = "inside a!"
>     def function():
>         print(x)
> with NameSpace(globals()) as b:
>     x = "inside b!"
>     def function():
>         print(x)
> 
> x = "inside main!"
> a.function()
> b.function()
> 
> 

It would have to be `a.x = ...` and `b.x = ...` with corresponding 
`print(a.x)` and `print(b.x)`.

Hrm -- and functions/classes/etc would have to refer to each other that 
way as well inside the namespace... not sure I'm in love with that...

~Ethan~



More information about the Python-list mailing list