Favorite non-python language trick?
D H
d at e.f
Fri Jun 24 11:02:34 EDT 2005
infidel wrote:
>>def class Colour:
>> def __init__(self, blue=0, green=0, red=0):
>> # pseudo-Python code borrowing concept "with" from Pascal
>> with self:
>> blue = blue
>> green = green
>> red = red
>>
>>And now you can see why Python doesn't support this idiom.
>
>
> Maybe it would make more sense if it was done a la Visual Basic
>
> with self:
> .blue = blue
> .green = green
> .red = red
>
> requiring a dot to be typed removes the ambiguity and gives the IDEs a
> chance to Intellisense-ify your coding.
Some made a python recipe emulating this I believe. The python cookbook
search engine is down though so I cannot find the link.
At one point Guido van Rossum was advocating this use of "with" as well,
I believe:
http://mail.python.org/pipermail/python-dev/2004-March/043545.html
But I don't think it is being considered now. I think now "with" is
being proposed for something more like VB and C#'s "using" statement.
It automatically disposes of a resource when done with it:
http://wiki.python.org/moin/WithStatement
More information about the Python-list
mailing list