Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.05; 'python': 0.08; 'global,': 0.09; 'okay': 0.09; '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; 'undefined': 0.09; 'def': 0.13; '456': 0.16; '>how': 0.16; 'bieber': 0.16; 'email addr:ix.netcom.com': 0.16; 'email name:wlfraed': 0.16; 'from:addr:ix.netcom.com': 0.16; 'from:addr:wlfraed': 0.16; 'from:name:dennis lee bieber': 0.16; 'message-id:@4ax.com': 0.16; 'received:wlfraed': 0.16; 'subject:function': 0.16; 'subject:variable': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'wulfraed': 0.16; "wouldn't": 0.17; 'wrote:': 0.18; 'jan': 0.19; 'tells': 0.21; 'url:home': 0.21; 'assigning': 0.23; 'received:166': 0.23; 'sat,': 0.25; 'module': 0.26; 'function': 0.27; 'variable': 0.28; 'lee': 0.28; 'error': 0.29; 'definition': 0.30; 'far,': 0.30; 'header:X-Complaints-To:1': 0.33; 'to:addr :python-list': 0.34; 'charset:us-ascii': 0.37; 'using': 0.38; 'references': 0.38; 'received:org': 0.38; 'to:addr:python.org': 0.40; 'within': 0.60; 'more': 0.61; '2012': 0.67; 'dennis': 0.73; '-0800': 0.84; '789': 0.84; 'subject:Calling': 0.84; 'local,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Calling a variable inside a function of another class Date: Sat, 07 Jan 2012 14:03:36 -0500 References: <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com> <4f086c52$0$29966$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: mobile-166-147-100-066.mycingular.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325963033 news.xs4all.nl 6897 [2001:888:2000:d::a6]:40075 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18653 On Sat, 7 Jan 2012 08:18:10 -0800 (PST), Yigit Turgut wrote: >How about assigning the variable as global, wouldn't it be more >effective? "global somename" only tells the Python interpreter that all references WITHIN a function definition to "somename" really are references to "somename" at the MODULE level. -=-=-=-=- amodule.py name1 = 123 name2 = 456 name3 = 789 def afunc(x): global name1 z = x + name1 #okay, it is using the module name1 name1 = z #still okay y = x + name2 #okay so far, will look up to the module level e = y + name3 #due to the next line, this will error name3 = e #no global, name3 is local, and above is undefined -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/