Creating a local variable scope.
Johan Grönqvist
johan.gronqvist at gmail.com
Sat Sep 19 03:51:32 EDT 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
> 2
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.
Thanks!
Johan
More information about the Python-list
mailing list