user-supplied locals dict for function execution?

Alex Martelli aleaxit at yahoo.com
Tue Mar 21 11:45:18 EST 2006


Lonnie Princehouse <finite.automaton at gmail.com> wrote:
   ...
> @namespace   # indicates function should be executed in namespace
> def initialize_namespace():
>   x = 5
> 
> # versus the alternative
> 
> __namespace__ = {
>   'x' : 5,
> }

Hm, what about:

ns = namespace(x=5)

and perhaps later

ns.update(y=6)

if you need to add a name to ns?  You can start with 'namespace=dict'
(in whatever ubernamespace you'd define your @namespace decorator above)
and change it later in any way you wish -- and it's vastly less
blackmagical, too.


Alex



More information about the Python-list mailing list