Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'rules.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'statement.': 0.09; 'subject:2.7': 0.09; 'from:addr:yahoo.com.ar': 0.16; 'function?': 0.16; 'parks': 0.16; 'scope,': 0.16; 'scope.': 0.16; 'travis': 0.16; 'wrote:': 0.16; 'wed,': 0.17; 'defined': 0.19; '(which': 0.19; 'gregory': 0.23; 'sep': 0.23; 'pm,': 0.24; 'variable': 0.24; 'aug': 0.24; 'statement': 0.25; 'function': 0.27; 'problem': 0.28; 'module.': 0.29; 'ewing': 0.30; 'kelly': 0.30; 'class': 0.30; "didn't": 0.31; 'despite': 0.32; 'does': 0.32; 'to:addr:python-list': 0.33; 'rules': 0.34; 'header:User- Agent:1': 0.34; 'header:X-Complaints-To:1': 0.35; 'url:python': 0.36; 'fri,': 0.36; 'doing': 0.36; 'received:org': 0.38; 'url:org': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'header :Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'body': 0.61; '31,': 0.64; 'strange': 0.68; 'received:190': 0.76; 'introduce': 0.79; '*does*': 0.84; '-0300,': 0.84; 'branches.': 0.84; 'genellina': 0.84; 'url:reference': 0.84; 'gabriel': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Gabriel Genellina" Subject: Re: Handling 2.7 and 3.0 Versions of Dict Date: Fri, 02 Sep 2011 17:29:59 -0300 References: <50924476-9ada-487e-bd4b-5b77bce11d5b@gz5g2000vbb.googlegroups.com> <4E5E051B.8060002@v.loewis.de> <9c7utuF8q8U1@mid.individual.net> <93c5378e-03f8-4764-96e8-2c3e8568baec@z8g2000yqe.googlegroups.com> <42b6b7cb-d659-4921-bec9-6a43671848e2@s20g2000yql.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 190.2.4.25 User-Agent: Opera Mail/11.51 (Win32) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314995369 news.xs4all.nl 2544 [2001:888:2000:d::a6]:49974 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12673 En Fri, 02 Sep 2011 13:53:37 -0300, Travis Parks escribió: > On Sep 2, 12:36 pm, "Gabriel Genellina" > wrote: >> En Wed, 31 Aug 2011 22:28:09 -0300, Travis Parks >> escribi : >> >> > On Aug 31, 7:37 pm, Gregory Ewing wrote: >> >> Ian Kelly wrote: >> >> > if sys.version_info < (3,): >> >> > getDictValues = dict.itervalues >> >> > else: >> >> > getDictValues = dict.values >> >> >> > (which is basically what the OP was doing in the first place). >> >> > My problem was that I didn't understand the scoping rules. It is still >> > strange to me that the getValues variable is still in scope outside >> > the if/else branches. >> >> Those if/else are at global scope. An 'if' statement does not introduce >> a new scope; so getDictValues, despite being "indented", is defined at >> global scope, and may be used anywhere in the module. > > Does that mean the rules would be different inside a function? Yes: a function body *does* create a new scope, as well as the class statement. See http://docs.python.org/reference/executionmodel.html -- Gabriel Genellina