Favorite non-python language trick?
d at e.f
Fri Jun 24 17:02:34 CEST 2005
>>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,
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:
More information about the Python-list