Creating a local variable scope.
johan.gronqvist at gmail.com
Sat Sep 19 09:51:32 CEST 2009
Sean DiZazzo skrev:
> I would do something like this:
>>>> class Namespace(object):
> ... pass
>>>> n = Namespace()
>>>> n.f = 2
>>>> n.g = 4
>>>> print f
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> NameError: name 'f' is not defined
>>>> print n.f
I like this solution. This also minimizes the extra code if I would want
to explicitly delete the bindings, as I would only need one line to
delete the Namespace object.
More information about the Python-list