namespace hacking question

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Tue Oct 5 02:42:20 CEST 2010

In message <mailman.1218.1285868424.29448.python-list at>, MRAB 

> An alternative is to create a namespace in an instance of a class and
> then add attributes to it:
> class Namespace(object):
>      pass
> n = Namespace()
> for v in ('spam', 'ham', 'eggs'):
>      setattr(n, v, init(v))
> foo(n.spam)
> bar(n.ham)
> baz(n.eggs)

I’d add my vote to this. If you want to hack a namespace, make your own, 
don’t try to mess with the unqualified local or global namespaces.

And as above, you can use a short prefix to save typing.

More information about the Python-list mailing list