Re: amazing scope?

2012-11-30 Thread Dave Angel
On 11/30/2012 11:05 AM, andrea crotti wrote: > Well I knew that this works fine, even if I feel a bit guilty to do > this, and better is: > > foo = 'bar' if some_condition else 'baz' > > Anyway for me the suprise is that something that is defined *later* at > the module scope is found in a function

RE: amazing scope?

2012-11-30 Thread Prasad, Ramit
andrea crotti > > I wrote a script, refactored it and then introducing a bug as below: > > def record_things(): > out.write("Hello world") > > if __name__ == '__main__': > with open('output', 'w') as out: > record_things() > > > but the shocking thing is that it didn't actually

Re: amazing scope?

2012-11-30 Thread Jean-Michel Pichavant
- Original Message - > Well I knew that this works fine, even if I feel a bit guilty to do > this, and better is: > > foo = 'bar' if some_condition else 'baz' > > Anyway for me the suprise is that something that is defined *later* > at > the module scope is found in a function which is de

Re: amazing scope?

2012-11-30 Thread Chris Angelico
On Sat, Dec 1, 2012 at 3:05 AM, andrea crotti wrote: > Well I knew that this works fine, even if I feel a bit guilty to do > this, and better is: > > foo = 'bar' if some_condition else 'baz' > > Anyway for me the suprise is that something that is defined *later* at > the module scope is found in a

Re: amazing scope?

2012-11-30 Thread Ulrich Eckhardt
Am 30.11.2012 12:11, schrieb andrea crotti: I wrote a script, refactored it and then introducing a bug as below: def record_things(): out.write("Hello world") This is a function. Since "out" is not a local variable, it is looked up in the surrounding namespace at the time the function is

Re: amazing scope?

2012-11-30 Thread Jean-Michel Pichavant
- Original Message - > 2012/11/30 andrea crotti : > > Already changing it to: > > def record_things(): > out.write("Hello world") > > def main(): > with open('output', 'w') as out: > record_things() > > if __name__ == '__main__': > main() > > makes it stops workin

Re: amazing scope?

2012-11-30 Thread Jean-Michel Pichavant
- Original Message - > I wrote a script, refactored it and then introducing a bug as below: > > def record_things(): > out.write("Hello world") > > if __name__ == '__main__': > with open('output', 'w') as out: > record_things() > > > but the shocking thing is that it did