Favorite non-python language trick?
Nicolas Fleury
nidoizo at yahoo.com
Sat Jun 25 15:44:14 EDT 2005
Steven D'Aprano wrote:
> One of the things I liked in Pascal was the "with" keyword. You could
> write something like this:
>
> with colour do begin
> red := 0; blue := 255; green := 0;
> end;
>
> instead of:
>
> colour.red := 0; colour.blue := 255; colour.green := 0;
>
> Okay, so maybe it is more of a feature than a trick, but I miss it and it
> would be nice to have in Python.
>
With PEP343 (I guess in Python 2.5), you will be able to do something like:
with renamed(colour) as c:
c.red = 0; c.blue = 255; c.green = 0
I think however it is bad. Better solutions to me would be:
colour.setRgb(0, 255, 0)
or
c = myVeryLongNameColour
c.red = 0; c.blue = 255; c.green = 0
Regards,
Nicolas
More information about the Python-list
mailing list