Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65114
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <glicerinu@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.026 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'value,': 0.04; 'explicitly': 0.05; 'assign': 0.07; 'guys!': 0.09; 'subject:Why': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'assume': 0.14; 'posted': 0.15; 'doing,': 0.16; 'obviously,': 0.16; 'which,': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '31,': 0.24; 'example.': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'constant': 0.31; 'marc': 0.31; 'fri,': 0.33; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'changing': 0.37; 'example,': 0.37; 'thank': 0.38; 'needed': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'tell': 0.60; 'tips': 0.61; 'full': 0.61; "you're": 0.61; 'you.': 0.62; 'complete': 0.62; 'name': 0.63; 'such': 0.63; '30,': 0.65; 'situation': 0.65; 'subject:this': 0.83; 'believe,': 0.84; 'local,': 0.84; 'cutting': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=RlNZjnoSczHK+ifCCE8Cn5xvYdv+cZsHGQwgJ605UVs=; b=FvVMXPjjtWL+xSilNif6/3eUBgRA5yfKvuMZ+36GDTzmF6o9csFKWIiZzSCHK/JEYE CF5bID68QKm3VXbQg8iGdvE1Rg/FmwFkr/BrqvozT17NA09UYyZG50E2gPSGBmF11rBq y9ZrY7lFIFy+PdlCdbIPudTXLIQo9eFDGWrwr9J9epVCIh0gUxR/6Y3flYtGwU4JBrjU hOjbiCxUPDPzf04KMA7A9w6YXBHVODcDN6XZPU3P+S8SVm5XxPb0dyGoeWNofGO/ZqZr cET1zvoY0WBAKYj0PDUSAc0tf2/g+2bLYegPrU7GHTUvrMF+/aynRU+h1qyIaJlf/VDh wCjw== |
| X-Received | by 10.112.136.36 with SMTP id px4mr1074919lbb.46.1391166338034; Fri, 31 Jan 2014 03:05:38 -0800 (PST) |
| MIME-Version | 1.0 |
| In-Reply-To | <CAPTjJmrVNgbwLMZ9yiv1qzVgexU5amMrNf3LM+NVAy_-qr5qQQ@mail.gmail.com> |
| References | <CA+DCN_tQsZDckkueO7FiVYKihy2b9=SdeALJ4RwrQN_uk0dDLQ@mail.gmail.com> <CAPTjJmrVNgbwLMZ9yiv1qzVgexU5amMrNf3LM+NVAy_-qr5qQQ@mail.gmail.com> |
| From | Marc Aymerich <glicerinu@gmail.com> |
| Date | Fri, 31 Jan 2014 12:05:17 +0100 |
| Subject | Re: Why this throws an UnboundLocalError ? |
| To | "comp.lang.python" <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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 | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6203.1391166346.18130.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1391166346 news.xs4all.nl 2870 [2001:888:2000:d::a6]:56094 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:65114 |
Show key headers only | View raw
On Thu, Jan 30, 2014 at 11:53 PM, Chris Angelico <rosuav@gmail.com> wrote: > On Fri, Jan 31, 2014 at 9:46 AM, Marc Aymerich <glicerinu@gmail.com> wrote: >> GLOBAL = 0 >> >> def update(): >> GLOBAL += 1 > > If you assign to a name, Python makes it local, unless you explicitly > tell it that you want it to be global: > > def update(): > global GLOBAL > GLOBAL += 1 > > But be aware that the ALL_CAPS name conventionally means a constant. > Since you're changing its value, it's not constant (wow! :) ), so > using a name of GLOBAL is a bad idea. (Also, obviously, you want to > name it appropriately to what you're doing, but I assume you called it > this as part of cutting down your example. For which, by the way, > thank you. You posted a complete example, and the full traceback, and > the Python version and platform. That's everything that we need to > help you - it's such a luxury!!) > Thank you very much guys! and for the additional tips Chris. :) I can't believe, all these years using Python and never encountered a situation where I needed to use global ! -- Marc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Why this throws an UnboundLocalError ? Marc Aymerich <glicerinu@gmail.com> - 2014-01-31 12:05 +0100
csiph-web