Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'assigning': 0.09; 'statements': 0.09; 'subject:Why': 0.09; 'subject:using': 0.09; 'cc:addr:python-list': 0.11; "wouldn't": 0.14; '"global"': 0.16; 'declaration': 0.16; 'skips': 0.16; 'statement.': 0.16; 'subject:Turtle': 0.16; 'subject:when': 0.16; 'think.': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'rid': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'statement': 0.30; 'code': 0.31; '(my': 0.31; 'received:google.com': 0.35; "didn't": 0.36; 'subject:?': 0.36; 'should': 0.36; 'needed': 0.38; 'subject:" ': 0.39; 'called': 0.40; 'john': 0.61; 'simply': 0.61; 'show': 0.63; 'name': 0.63; 'within': 0.65; 'subject:have': 0.80; 'subject:much': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=OdwRRx7id7T3x9e/h+OdSR67qTZkhWmC3KZmWJwL384=; b=TQdwUWRBYlkpooHtz8H+xu1dCCSm858y5qpu0g+yLtD/4OvgWuczuhCtyo1XqG3ZK7 zDzvAyoreEpEC6dumvvU4jYZ5osbOgdyDZnAxizlyJafjzyiv1JNMs3wOFc5jvsykrhk P8OJLb8S0w+lXlmlsfpqQNiiT+Cw86DZzDNUCEM8si85esrnGAa4IcznAcggi/1lfKDq 3CS/yGpwSZPn2v25WaztQfzkMPckSreI6cSGiTwVWKQWFF/XgXfCUYLAZDlTdTy2gKcu BAotSJ4r/WvxHrR+afOXRIv0pgWx0iElljhlb8IDXgkVctEhSeNIUBjL57uBRP1bp7Wd 1jdg== X-Received: by 10.229.213.1 with SMTP id gu1mr22907145qcb.13.1379847362316; Sun, 22 Sep 2013 03:56:02 -0700 (PDT) Sender: Ned Batchelder Date: Sun, 22 Sep 2013 06:56:02 -0400 From: Ned Batchelder User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: John Ladasky Subject: Re: Why do I have to use "global" so much when using Turtle? References: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> In-Reply-To: <0b028e65-37b2-492a-83c0-0d76d037c165@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379847370 news.xs4all.nl 15986 [2001:888:2000:d::a6]:60865 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54582 On 9/22/13 12:39 AM, John Ladasky wrote: > For a while, I had a "quit" function that I bound to the q key: > > sc.onkeypress(quit, "q") > > The quit function simply printed a message, and then called sc.bye(). As with move_balls, quit wouldn't work unless I had a "global sc" declaration in it. (My shortened program skips my function and just binds sc.bye to the q key, avoiding the need for globals.) It sounds like you didn't need as many global statements as you think. In particular, you only need to use "global" if you are assigning to a global name within a function. The quit function you describe didn't have a "sc = ..." statement in it, and so should not have needed a "global sc" statement. Can you show the code with the global statements? There's very likely a way to get rid of some of them. --Ned.