2008/7/3 Facundo Batista
2008/7/3 Stavros Korokithakis
: while my_file.read(1024) as data: do_something(data)
Python explicitly disallows inline assignment ("while a=myfile.read():") because of the error propensity when confusing it with the comparation ("=="). But here we're gaining the same advantage, without that risk.
For me, the main advantage of binding being provided by a statement rather than an expression is not that it eliminates confusion with test for equality. The main advantage is that it prevents *sneaky* (re)binding. You can't bind a name from within an expression, it has to be clearly advertised: foo = 'new value' When I'm scanning code later I'm not going to miss these. IMHO, giving that up would be a mistake. -- Arnaud