Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

Duncan Booth duncan.booth at invalid.invalid
Sat Apr 14 12:45:18 EDT 2007


"BJörn Lindqvist" <bjourne at gmail.com> wrote:

> ? Not having to bother with petty things like that is an advantage.
> Javascript has with-statements that are equivalent to your
> using-statements but from what I've seen most programmers avoid them.
> They don't increase readability one bit.

That is at least partly because Javascript with statements are badly 
broken. Consider the following code:

function setit(a) {
   with (a) { x = 1; };
   return a;
}
var x;
delete x;
alert(setit({'x':0}).x);
alert(setit({'y':0}).x);
alert(x);


If 'a' has a property 'x' setit updates the property, otherwise it searches 
out the scope chain until it finds an object with an 'x' property and 
finally creates one on the global object if there isn't one.

So the output in this case is the sequence '1', 'undefined', '1'.



More information about the Python-list mailing list