[Python-ideas] Add a feature similar to C++ "using some_namespace"
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Feb 7 22:37:47 CET 2011
Manuel Bärenz wrote:
> This could be easier to implement and read if we had something like:
>
> class Spam(object):
> def frobnicate(self):
> using self:
> eggs = buy_eggs()
> scrambled = scramble(eggs)
> return scrambled> 42
On the contrary, I think most people here would consider this to
be *harder* to read and maintain. It seems clear to you because
you just wrote it and it's fresh in your mind which namespaces
the various names belong to. But to someone else, it's far from
obvious, for example, whether 'scramble' is a method of self or
a module-level function.
It also interacts badly with Python's declaration-free determination
of name scope. What if you wanted 'eggs' or 'scrambled' to be local
variables rather than an attribute of self?
--
Greg
More information about the Python-ideas
mailing list