the annoying, verbose self
Colin J. Williams
cjw at sympatico.ca
Sun Nov 25 09:16:01 EST 2007
Andrew Koenig wrote:
> "Colin J. Williams" <cjw at sympatico.ca> wrote in message
> news:mailman.1557.1195995738.13605.python-list at python.org...
>
>> Alternatively, as someone else suggested, an analogue of the Pascal "with"
>> could be used:
>>
>> def abs(self):
>> with self:
>> return math.sqrt(x**2 + y**2 + z**2)
>
> How does your suggested "with" statement know to transform x into self.x but
> not transform math.sqrt into self.math.sqrt?
>
>
I am not advocating this, but this could be:
def abs(self):
with self:
with math:
return sqrt(x**2 + y**2 + z**2)
The idea being that "with self" use
creates a new namespace:
newGlobal= oldGlobal + oldLocal
newLocal= names from self
Similarly, "with math" creates a newer
namespace:
newerGlobal= newGlobal + newLocal
newerLocal= names from math
My guess is that there would be little
use for nesting the
"with".
Colin W.
More information about the Python-list
mailing list