Default scope of variables
rosuav at gmail.com
Mon Jul 8 07:14:06 CEST 2013
On Mon, Jul 8, 2013 at 3:00 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Mon, 08 Jul 2013 13:11:37 +1000, Chris Angelico wrote:
>> It's not something to be solved by the language, but it's often
>> something to be solved by the program's design. Two lines of code that
>> achieve the same goal should normally look the same. This is why
>> Python's policy is "one obvious way to do something" rather than "spell
>> it five different ways in the same file to make a nightmare for other
>> people coming after you". Why should database queries be spelled
>> "trans1.query()" in one place, and "trans2.query()" in another?
> Is that a trick question? They probably shouldn't. But it's a big leap
> from that to "...and therefore `for` and `while` should introduce their
> own scope".
No, it's not a trick question; I was responding to Ethan's suggestion
as well as yours, and he was saying pretty much that.
(maybe that'll reduce the confusion?)
More information about the Python-list