Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34096 > unrolled thread
| Started by | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| First post | 2012-11-30 12:31 +0100 |
| Last post | 2012-11-30 12:31 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
Re: amazing scope? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-11-30 12:31 +0100
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| Date | 2012-11-30 12:31 +0100 |
| Subject | Re: amazing scope? |
| Message-ID | <mailman.383.1354275082.29569.python-list@python.org> |
----- Original Message -----
> 2012/11/30 andrea crotti <andrea.crotti.0@gmail.com>:
>
> 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 working as expected, so it's really just a corner case
> of using the if __name__ == '__main__'
> which I had never encountered before..
You do realize that
foo = 5 # define at the module level
if __name__ == '__main__':
bar = 6 # also at the module level
if True:
ham = 8 # still at the module level
def func()
# scope has changed, only at the func level
jam = 9
Nothing magic about if __name__ == '__main__'
Cheers,
JM
-- IMPORTANT NOTICE:
The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Back to top | Article view | comp.lang.python
csiph-web