Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34096

Re: amazing scope?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=674d5ed43=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.022
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; '__name__': 0.07; 'main()': 0.07; 'stops': 0.07; "'w')": 0.09; 'func': 0.09; 'def': 0.10; 'to:name:python-list': 0.15; "'__main__':": 0.16; 'expected,': 0.16; 'main():': 0.16; 'true:': 0.16; 'module': 0.19; 'define': 0.20; 'cheers,': 0.23; 'to:2**1': 0.23; 'header:In-Reply-To:1': 0.25; 'realize': 0.27; '-----': 0.32; 'to:addr:python-list': 0.33; 'subject:?': 0.35; 'really': 0.36; 'thank': 0.36; 'level': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'you.': 0.61; 'received:194': 0.61; 'information': 0.63; 'person,': 0.65; 'disclose': 0.69; 'notice:': 0.71; 'privileged.': 0.72; 'andrea': 0.84; 'medium.': 0.91
X-IronPort-AV E=Sophos;i="4.83,347,1352070000"; d="scan'208";a="950729"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Fri, 30 Nov 2012 12:31:49 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To andrea crotti <andrea.crotti.0@gmail.com>, python-list <python-list@python.org>
In-Reply-To <CAF_E5JZxgq=vAw8vZdQqYzvXKm3+49kWwQSS6caOMtvcO8yvMQ@mail.gmail.com>
Subject Re: amazing scope?
MIME-Version 1.0
X-Mailer Zimbra 7.2.0_GA_2669 (ZimbraWebClient - GC7 (Linux)/7.2.0_GA_2669)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.383.1354275082.29569.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1354275082 news.xs4all.nl 6922 [2001:888:2000:d::a6]:42713
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34096

Show key headers only | View raw



----- 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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: amazing scope? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-11-30 12:31 +0100

csiph-web