Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34104 > unrolled thread
| Started by | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
|---|---|
| First post | 2012-11-30 19:21 +0000 |
| Last post | 2012-11-30 19:21 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: amazing scope? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-30 19:21 +0000
| From | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
|---|---|
| Date | 2012-11-30 19:21 +0000 |
| Subject | RE: amazing scope? |
| Message-ID | <mailman.390.1354303336.29569.python-list@python.org> |
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 stopped working, it
> still works perfectly!
>
> What my explanation might be is that the "out" is declared at module
> level somehow,
> but that's not really intuitive and looks wrong, and works both on
> Python 2.7 and 3.2..
Makes sense to me. `out` is declared in an if statement. If statements
have no "scope" and it is not in a function so it gets added to the
module's namespace.
~Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
Back to top | Article view | comp.lang.python
csiph-web