Re: Curious case of UnboundLocalError

2018-03-31 Thread Peter Otten
Johannes Bauer wrote: > On 30.03.2018 13:25, Johannes Bauer wrote: > >>> This mention of collections refers to ... >>> } for (_, collections) in z.items(): >>> >>> ... this local variable. >> >> Yup, but why? I mean, at the point of definition of "z", the only >> definition of "collect

Re: Curious case of UnboundLocalError

2018-03-31 Thread Johannes Bauer
On 30.03.2018 16:46, Ben Bacarisse wrote: >> Yup, but why? I mean, at the point of definition of "z", the only >> definition of "collections" that would be visible to the code would be >> the globally imported module, would it not? How can the code know of the >> local declaration that only comes

Re: Curious case of UnboundLocalError

2018-03-30 Thread Terry Reedy
On 3/30/2018 7:25 AM, Johannes Bauer wrote: On 30.03.2018 13:13, Ben Bacarisse wrote: import collections class Test(object): def __init__(self): z = { "y": collections.defaultdict(list), This mention of collections refers to ...

Re: Curious case of UnboundLocalError

2018-03-30 Thread Ben Bacarisse
Johannes Bauer writes: > On 30.03.2018 13:13, Ben Bacarisse wrote: > >>> import collections >>> >>> class Test(object): >>> def __init__(self): >>> z = { >>> "y": collections.defaultdict(list), >> >> This mention of collections refers to ... >> >>>

Re: Curious case of UnboundLocalError

2018-03-30 Thread Johannes Bauer
On 30.03.2018 13:25, Johannes Bauer wrote: >> This mention of collections refers to ... >> >>> } >>> for (_, collections) in z.items(): >> >> ... this local variable. > > Yup, but why? I mean, at the point of definition of "z", the only > definition of "collections" that w

Re: Curious case of UnboundLocalError

2018-03-30 Thread Chris Angelico
On Fri, Mar 30, 2018 at 9:24 PM, Johannes Bauer wrote: > Hey group, > > I stumbled about something that I cannot quite explain while doing some > stupid naming of variables in my code, in particular using "collections" > as an identifier. However, what results is strange. I've created a > minimal

Re: Curious case of UnboundLocalError

2018-03-30 Thread Johannes Bauer
On 30.03.2018 13:13, Ben Bacarisse wrote: >> import collections >> >> class Test(object): >> def __init__(self): >> z = { >> "y": collections.defaultdict(list), > > This mention of collections refers to ... > >> } >> for (_, collec

Re: Curious case of UnboundLocalError

2018-03-30 Thread Ben Bacarisse
> In my opinion, this should run. However, this is what happens on Python > 3.6.3 (default, Oct 3 2017, 21:45:48) [GCC 7.2.0] on linux): > > Traceback (most recent call last): > File "x.py", line 11, in > Test() > File "x.py", line 6, in __ini

Curious case of UnboundLocalError

2018-03-30 Thread Johannes Bauer
t happens on Python 3.6.3 (default, Oct 3 2017, 21:45:48) [GCC 7.2.0] on linux): Traceback (most recent call last): File "x.py", line 11, in Test() File "x.py", line 6, in __init__ "y": collections.defaultdict(list), UnboundLocalError: local variable 'coll

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-19 Thread Terry Reedy
On 3/19/2015 4:23 AM, Chris Kavanagh wrote: On Wednesday, March 18, 2015 at 5:37:53 PM UTC-4, Terry Reedy wrote: You comment out apparently irrelevant lines and see if you still have the same problem, and if you do, delete. Repeat until you have a Minimal Complete Verifiable Example. Thank

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-19 Thread Chris Kavanagh
On Wednesday, March 18, 2015 at 5:37:53 PM UTC-4, Terry Reedy wrote: > On 3/18/2015 3:42 PM, Chris Kavanagh wrote: > > > 2nd, you say you "don't want to play guessing games", yet complain > > about "300 lines of irrelevant code", lol. Which way is it? Do you > > want the code, or not? How do I kno

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-19 Thread Chris Kavanagh
On Wednesday, March 18, 2015 at 5:50:49 PM UTC-4, Mark Lawrence wrote: > On 18/03/2015 19:42, Chris Kavanagh wrote: > > > > 2nd, you say you "don't want to play guessing games", yet complain about > > "300 lines of irrelevant code", lol. Which way is it? Do you want the code, > > or not? How do

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-19 Thread Chris Kavanagh
On Wednesday, March 18, 2015 at 6:38:48 PM UTC-4, Steven D'Aprano wrote: > On Thu, 19 Mar 2015 06:42 am, Chris Kavanagh wrote: > > > While I appreciate the help greatly I thought I had put the entire > > traceback of the error. I was posting here and on StackOverflow, and > > suppose I got confuse

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-18 Thread Steven D'Aprano
On Thu, 19 Mar 2015 06:42 am, Chris Kavanagh wrote: > While I appreciate the help greatly I thought I had put the entire > traceback of the error. I was posting here and on StackOverflow, and > suppose I got confused. We all make mistakes. I got distracted and forgot to link you to http://sscce

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-18 Thread Mark Lawrence
On 18/03/2015 19:42, Chris Kavanagh wrote: 2nd, you say you "don't want to play guessing games", yet complain about "300 lines of irrelevant code", lol. Which way is it? Do you want the code, or not? How do I know what's relevant or irrelevant when I'm clearly confused? On Stack, if you don'

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-18 Thread Terry Reedy
On 3/18/2015 3:42 PM, Chris Kavanagh wrote: 2nd, you say you "don't want to play guessing games", yet complain about "300 lines of irrelevant code", lol. Which way is it? Do you want the code, or not? How do I know what's relevant or irrelevant when I'm clearly confused? You comment out appare

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-18 Thread Chris Kavanagh
ad of an Int) the showinfo dialogue box > > opens as it should, but when the user clicks "ok" in the box, I get the > > error "UnboundLocalError: local variable 'age' referenced before > > assignment". > > As much as I love guessing games, I re

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-18 Thread Steven D'Aprano
or: > showinfo("Error:", "Please Enter A Number In Age Field.") > > If the user inputs a string (instead of an Int) the showinfo dialogue box > opens as it should, but when the user clicks "ok" in the box, I get the > error "UnboundL

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-18 Thread ckava3
showinfo dialogue > > box opens as it should, but when the user clicks "ok" in the box, I get > > the error "UnboundLocalError: local variable 'age' referenced before > > assignment". I tried using a default value above the try: except clause > > (age=0), wh

Re: UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-17 Thread MRAB
ter A Number In Age Field.") If the user inputs a string (instead of an Int) the showinfo dialogue box opens as it should, but when the user clicks "ok" in the box, I get the error "UnboundLocalError: local variable 'age' referenced before assignment". I tried using

UnboundLocalError in TKinter, SQLAlchemy script.

2015-03-17 Thread Chris Kavanagh
ts a string (instead of an Int) the showinfo dialogue box opens as it should, but when the user clicks "ok" in the box, I get the error "UnboundLocalError: local variable 'age' referenced before assignment". I tried using a default value above the try: except clause (a

Re: Why this throws an UnboundLocalError ?

2014-01-31 Thread Skip Montanaro
> That might be an indication of good code design :) Or he got lucky and all his previous globals were mutable. :) Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Why this throws an UnboundLocalError ?

2014-01-31 Thread Chris Angelico
On Fri, Jan 31, 2014 at 10:05 PM, Marc Aymerich wrote: > I can't believe, all these years using Python and never encountered a > situation where I needed to use global ! That might be an indication of good code design :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Why this throws an UnboundLocalError ?

2014-01-31 Thread Marc Aymerich
On Thu, Jan 30, 2014 at 11:53 PM, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 9:46 AM, Marc Aymerich 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():

Re: Why this throws an UnboundLocalError ?

2014-01-30 Thread Ned Batchelder
"help", "copyright", "credits" or "license" for more information. import globalstate globalstate.update() Traceback (most recent call last): File "", line 1, in File "globalstate.py", line 4, in update GLOBAL += 1 UnboundLocalError: l

Re: Why this throws an UnboundLocalError ?

2014-01-30 Thread Mark Lawrence
"help", "copyright", "credits" or "license" for more information. import globalstate globalstate.update() Traceback (most recent call last): File "", line 1, in File "globalstate.py", line 4, in update GLOBAL += 1 UnboundLocalError: l

Re: Why this throws an UnboundLocalError ?

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 9:46 AM, Marc Aymerich 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

Why this throws an UnboundLocalError ?

2014-01-30 Thread Marc Aymerich
credits" or "license" for more information. >>> import globalstate >>> globalstate.update() Traceback (most recent call last): File "", line 1, in File "globalstate.py", line 4, in update GLOBAL += 1 UnboundLocalError: local variable 'GL

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread John Gordon
In Dave Angel writes: > > The problem is that change() isn't being executed here; instead it's being > > executed from within root.mainloop(), whenever the user presses button-1. > > > > And within root.mainloop(), there is no variable called isWhite. > > > Actually that's irrelevant. Whether

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Dave Angel
isWhite = False else: w.itemconfig(rect, fill="white") isWhite = True w.bind("", change) root.mainloop() The problem occurs when clicking on the white square. The following error appears: "if isWhite: UnboundLocalError: local

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Joshua Landau
On 24 June 2013 21:19, wrote: > Thank's to you all! > > Setting isWhite as global worked fine. > I'll probably be back soon with another silly question, see you then :) By the way, it's normally bad to use globals like this. When you're learning it's something you just do, though; it's fine for

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Joshua Landau
On 24 June 2013 21:12, John Gordon wrote: > Since you're new to programming, this might be a bit tricky to explain, > but I'll do my best. :-) > > The problem is that change() isn't being executed here; instead it's being > executed from within root.mainloop(), whenever the user presses button-1.

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Joshua Landau
Here's a little test to make sure you understand (this is one of the most confusing parts of Python's closures in my opinion): foo = "I'm foo!" def working(): print(foo) def broken(): print(foo) if False: # There's no way this could cause a problem! foo = "This will *never*

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread pablobarhamalzas
Thank's to you all! Setting isWhite as global worked fine. I'll probably be back soon with another silly question, see you then :) -- http://mail.python.org/mailman/listinfo/python-list

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread John Gordon
isWhite = False > else: > w.itemconfig(rect, fill="white") > isWhite = True > > w.bind("", change) > > root.mainloop() > The problem occurs when clicking on the white square. The

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Antoon Pardon
l="blue") isWhite = False else: w.itemconfig(rect, fill="white") isWhite = True w.bind("", change) root.mainloop() The problem occurs when clicking on the white square. The following error appears: "if isWhite: UnboundL

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Peter Otten
> w.bind("", change) > > root.mainloop() > > > The problem occurs when clicking on the white square. The following error > appears: "if isWhite: > UnboundLocalError: local variable 'isWhite' referenced before assignment" > > How

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread pablobarhamalzas
Just before anyone says, the reason I bind to the Canvas instead of binding directly to the rectangle is because I plan to add more squares in the future. Cheers. -- http://mail.python.org/mailman/listinfo/python-list

What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread pablobarhamalzas
False else: w.itemconfig(rect, fill="white") isWhite = True w.bind("", change) root.mainloop() The problem occurs when clicking on the white square. The following error appears: "if isWhite: UnboundLocalError

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread danieldelay
Le 08/06/2010 10:03, ch1zra a écrit : import os, time, re, pyodbc, Image, sys from datetime import datetime, date, time from reportlab.lib.pagesizes import A4 from reportlab.lib.units import cm from reportlab.pdfgen import canvas from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttf

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Bruno Desthuilliers
ch1zra a écrit : On Jun 8, 10:59 am, Bryan wrote: Python doesn't have one global namespace. Each module (file) has its own namespace, which is a Python dict, and 'global' means defined in the containing module's dict. Put the import: from reportlab.pdfgen import canvas in the mkTable.py fil

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Bryan
of this expression > > is completely undefined, resulting in the error you're getting. > > The above would produce a NameError, not an UnboundLocalError: Ah, yes. The OP's code produces a NameError. [...] > To get the latter you'd have to omit the global declaration. Not h

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Peter Otten
t; canvas = canvas.Canvas(fname, pagesize=A4) >>> > ... and so on >>> >>> > this gives me following traceback: >>> >>> > Traceback (most recent call last): >>> > File "C:\py\pdf_test.py", line 36, in >>> > mkTable

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
def mkTable(): > >     global canvas > >     canvas = canvas.Canvas(fname, pagesize=A4) > >     ... and so on > > > this gives me following traceback: > > > Traceback (most recent call last): > >   File "C:\py\pdf_test.py", line 36, in > >     mkTa

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Chris Rebert
t; this gives me following traceback: >> >> > Traceback (most recent call last): >> >   File "C:\py\pdf_test.py", line 36, in >> >     mkTable.mkTable() >> >   File "C:\py\mkTable.py", line 38, in mkTable >> >     canvas = canva

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
y\pdf_test.py", line 36, in > >     mkTable.mkTable() > >   File "C:\py\mkTable.py", line 38, in mkTable > >     canvas = canvas.Canvas("K_lista.pdf", pagesize=A4) > > UnboundLocalError: local variable 'canvas' referenced before > &g

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Bryan
o on > > this gives me following traceback: > > Traceback (most recent call last): >   File "C:\py\pdf_test.py", line 36, in >     mkTable.mkTable() >   File "C:\py\mkTable.py", line 38, in mkTable >     canvas = canvas.Canvas("K_lista.pdf", pa

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Richard Thomas
ze=A4) >     ... and so on > > this gives me following traceback: > > Traceback (most recent call last): >   File "C:\py\pdf_test.py", line 36, in >     mkTable.mkTable() >   File "C:\py\mkTable.py", line 38, in mkTable >     canvas = canvas.Canvas("K_

UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
st.py", line 36, in mkTable.mkTable() File "C:\py\mkTable.py", line 38, in mkTable canvas = canvas.Canvas("K_lista.pdf", pagesize=A4) UnboundLocalError: local variable 'canvas' referenced before assignment i haven't posted entire code, because those li

Re: UnboundLocalError: local variable '_[1]' referenced before assignment

2009-12-09 Thread Dave Angel
Gabriel Rossetti wrote: Dave Angel wrote: Gabriel Rossetti wrote: Hello everyone, I get this error on python 2.6.1 on mac os x 10.6 : UnboundLocalError: local variable '_[1]' referenced before assignment here's the code that raises this: params = [ self.__formatData(param

Re: UnboundLocalError: local variable '_[1]' referenced before assignment

2009-12-09 Thread Terry Reedy
Gabriel Rossetti wrote: Gabriel Rossetti wrote: I get this error on python 2.6.1 on mac os x 10.6 : UnboundLocalError: local variable '_[1]' referenced before assignment here's the code that raises this: params = [ self.__formatData(paramProcFunc, query, p) for p in params

Re: UnboundLocalError: local variable '_[1]' referenced before assignment

2009-12-09 Thread Hrvoje Niksic
Richard Thomas writes: > That isn't an error that should occur, not least because _[1] isn't a > valid name. Can you post a full traceback? The name _[n] is used internally when compiling list comprehensions. The name is chosen precisely because it is not an (otherwise) valid identifier. For ex

Re: UnboundLocalError: local variable '_[1]' referenced before assignment

2009-12-09 Thread Gabriel Rossetti
Dave Angel wrote: Gabriel Rossetti wrote: Hello everyone, I get this error on python 2.6.1 on mac os x 10.6 : UnboundLocalError: local variable '_[1]' referenced before assignment here's the code that raises this: params = [ self.__formatData(paramProcFunc, query, p)

Re: UnboundLocalError: local variable '_[1]' referenced before assignment

2009-12-09 Thread Bruno Desthuilliers
Richard Thomas a écrit : On Dec 9, 10:17 am, Gabriel Rossetti wrote: UnboundLocalError: local variable '_[1]' referenced before assignment That isn't an error that should occur, not least because _[1] isn't a valid name It's an internal identifier used in l

Re: UnboundLocalError: local variable '_[1]' referenced before assignment

2009-12-09 Thread Dave Angel
Gabriel Rossetti wrote: Hello everyone, I get this error on python 2.6.1 on mac os x 10.6 : UnboundLocalError: local variable '_[1]' referenced before assignment here's the code that raises this: params = [ self.__formatData(paramProcFunc, query, p) for p in params ] what

Re: UnboundLocalError: local variable '_[1]' referenced before assignment

2009-12-09 Thread Richard Thomas
On Dec 9, 10:17 am, Gabriel Rossetti wrote: > Hello everyone, > > I get this error on python 2.6.1 on mac os x 10.6 : > > UnboundLocalError: local variable '_[1]' referenced before assignment > > here's the code that raises this: > > params = [ self.__fo

UnboundLocalError: local variable '_[1]' referenced before assignment

2009-12-09 Thread Gabriel Rossetti
Hello everyone, I get this error on python 2.6.1 on mac os x 10.6 : UnboundLocalError: local variable '_[1]' referenced before assignment here's the code that raises this: params = [ self.__formatData(paramProcFunc, query, p) for p in params ] what I don't get is that i

Re: UnboundLocalError with extra code after return

2009-09-30 Thread John Posner
Duncan Booth wrote: / class CallableOnlyOnce(object): /def __init__(self, func): self.func = func def __call__(self): f = self.func if f: self.func = None return f() / def callonce(func): / return CallableOnlyOnce(func) / @callonce /

Re: UnboundLocalError with extra code after return

2009-09-30 Thread Duncan Booth
Rich Healey wrote: > It seems that my problem was that I can't assign a new function to the > name func within the callonce() function. I can however interact with > the func object (in this case storing information about whether or not > I'd called it in it's __RECALL item. > > Is there a clean

Re: UnboundLocalError with extra code after return

2009-09-29 Thread Albert Hopkins
print "T2 called" > t2() > > Gives me: > > C:\tmp\callonce>callonce.py > Traceback (most recent call last): > File "C:\tmp\callonce\callonce.py", line 27, in > t2() > File "C:\tmp\callonce\callonce.py", line 12, in __ > r

Re: UnboundLocalError with extra code after return

2009-09-29 Thread Chris Rebert
On Tue, Sep 29, 2009 at 9:41 PM, Chris Rebert wrote: > On Tue, Sep 29, 2009 at 9:15 PM, Rich Healey wrote: >> However: >> >> def callonce(func): >>    def nullmethod(): pass >>    def __(): >>        return func() >>        func = nullmethod Additionally, to rebind a variable in an outer nested

Re: UnboundLocalError with extra code after return

2009-09-29 Thread Chris Rebert
On Tue, Sep 29, 2009 at 9:15 PM, Rich Healey wrote: > However: > > def callonce(func): >    def nullmethod(): pass >    def __(): >        return func() >        func = nullmethod When Python sees this assignment to func as it compiles the __() method, it marks func as a local variable and will n

Re: UnboundLocalError with extra code after return

2009-09-29 Thread Rich Healey
nce > def t2(): >     print "T2 called" > t2() > > Gives me: > > C:\tmp\callonce>callonce.py > Traceback (most recent call last): >   File "C:\tmp\callonce\callonce.py", line 27, in >     t2() >   File "C:\tmp\callonce\callonce.py", li

UnboundLocalError with extra code after return

2009-09-29 Thread Rich Healey
t2() File "C:\tmp\callonce\callonce.py", line 12, in __ return func() UnboundLocalError: local variable 'func' referenced before assignment Any ideas on why? This looks like a bug to me, but I'm quite new to this style of programming so it may be some nuance I'm

Re: UnboundLocalError - (code is short & simple)

2009-09-28 Thread New User
illiers wrote: From: Bruno Desthuilliers Subject: Re: UnboundLocalError - (code is short & simple) To: python-list@python.org Date: Monday, September 28, 2009, 8:24 AM Chris Rebert a écrit : > On Sun, Sep 27, 2009 at 8:5

Re: UnboundLocalError - (code is short & simple)

2009-09-28 Thread New User
rtin --- On Mon, 9/28/09, Chris Kaynor wrote: From: Chris Kaynor Subject: Re: UnboundLocalError - (code is short & simple) To: python-list@python.org Date: Monday, September 28, 2009, 4:00 PM On Sun, Sep 27, 2009 at 10:39 PM, New User wrote: Hi Chris, Thank you for the reply and info!

Re: UnboundLocalError - (code is short & simple)

2009-09-28 Thread Chris Kaynor
on the python list - I just forgot to remove you from it (I used G-Mail's reply all). In general, unless the reply is off-topic or personal, it should be replied to on-list. This allows more people to both see the answer and to help further explain the answer. > > --- On *Mon, 9/28/09, Chris Ka

Re: UnboundLocalError - code is short & simple

2009-09-28 Thread Francesco Bochicchio
  File "", line 1, in >     toss_winner() >   File "C:/Python26/toss_winner.py", line 7, in toss_winner >     coin_toss = coin_toss() > UnboundLocalError: local variable 'coin_toss' referenced before > assignment > > Question #1: > > After reviewi

Re: UnboundLocalError - (code is short & simple)

2009-09-28 Thread Bruno Desthuilliers
_winner coin_toss = coin_toss() UnboundLocalError: local variable 'coin_toss' referenced before assignment --- # toss_winner.py from coin_toss import coin_toss def toss_winner(): coin_toss = coin_toss() When Python sees t

Re: UnboundLocalError - (code is short & simple)

2009-09-27 Thread Chris Rebert
toss_winner >    coin_toss = coin_toss() > UnboundLocalError: local variable 'coin_toss' referenced before > assignment > > --- > > # toss_winner.py > > from coin_toss import coin_toss > > def toss_winner

Re: UnboundLocalError - (code is short & simple)

2009-09-27 Thread Chris Kaynor
ot;Python Programming: An Intro to Computer Science" by Zelle. > > Thanks! > > --- > > Traceback (most recent call last): > File "", line 1, in >toss_winner() > File "C:/Pytho

UnboundLocalError - code is short & simple

2009-09-27 Thread pylearner
file is listed below.) Problem: I am getting an error when I run "toss_winner.py." Error Message: Traceback (most recent call last): File "", line 1, in toss_winner() File "C:/Python26/toss_winner.py", line 7, in toss_winner coin_toss = coin_toss() UnboundLocalE

UnboundLocalError - (code is short & simple)

2009-09-27 Thread pylearner
n. I'm currently self-studying "Python Programming: An Intro to Computer Science" by Zelle. Thanks! --- Traceback (most recent call last): File "", line 1, in toss_winner() File "C:/Python26/t

Re: confusing UnboundLocalError behaive

2009-02-23 Thread Steven D'Aprano
111 abc is local to test(). print(abc) looks for a local abc, can't find one, and so searches the higher scope, and finds it there. > 2. > def test(): > abc="111" > def m1(): > print(abc) > abc+="222" &g

Re: confusing UnboundLocalError behaive

2009-02-23 Thread Gabriel Genellina
anywhere in the function body, it's local". This is done by static analysis when the code is compiled. 2. def test(): abc="111" def m1(): print(abc) abc+="222" m1() test() Output: print(abc) UnboundLocalError

Re: confusing UnboundLocalError behaive

2009-02-23 Thread Chris Rebert
ut: 111 > > 2. > def test(): >abc="111" >def m1(): You need a 'nonlocal' declaration here (requires Python 3.0 I think). See PEP 3104 for more info -- http://www.python.org/dev/peps/pep-3104/ >print(abc) >

confusing UnboundLocalError behaive

2009-02-23 Thread neoedmund
abc+="222" m1() test() Output: print(abc) UnboundLocalError: local variable 'abc' referenced before assignment 3. def test2(): abc=[111] def m1(): print(abc) abc.append(222) m1() print(abc) test2()

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Terry Reedy
Andreas Tawn wrote: Terry Reedy wrote: For loop variables continue after the loop exits. This is intentional. I never knew that and I can't find reference to it in the docs. Can you help me with the reasons for it? 1. Python's reluctance to multiply scopes without necessity (as other re

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Fredrik Lundh
Andreas Tawn wrote: I don't have experience of too many other languages, but in C++ (and I guess C)... That's invalid C (you cannot declare variables in the "for" statement itself, at least not in C89). And back in the old days, some C++ compilers did in fact leak declarations from "for" lo

RE: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Andreas Tawn
> Andreas Tawn wrote: > > Terry Reedy wrote: > >> Wrong. > > Thank you. > > > >> For loop variables continue after the loop exits. This is > >> intentional. > > I never knew that and I can't find reference to it in the docs. > > Interesting starting point. It never occurred to me > that they

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Tim Golden
Andreas Tawn wrote: Terry Reedy wrote: Wrong. Thank you. For loop variables continue after the loop exits. This is intentional. I never knew that and I can't find reference to it in the docs. Interesting starting point. It never occurred to me that they might not. (So I didn't look for an

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Fredrik Lundh
Andreas Tawn wrote: I never knew that and I can't find reference to it in the docs. the for-in loop does ordinary assignments in the current scope: http://docs.python.org/ref/for.html "Each item in turn is assigned to the target list using the standard rules for assignments, and

RE: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Andreas Tawn
Terry Reedy wrote: >Wrong. Thank you. >For loop variables continue after the loop exits. This is >intentional. I never knew that and I can't find reference to it in the docs. Can you help me with the reasons for it? Drea -- http://mail.python.org/mailman/listinfo/python-list

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread Terry Reedy
Andreas Tawn wrote: I think a better explanation is that in your original function, x only existed while the for loop was running. As soon as execution hit the break statement, x ceased to exist. Wrong. For loop variables continue after the loop exits. This is intentional. Mensanator gav

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread norseman
(most recent call last): File "", line 1, in [isPrime(y) for y in range(11)] File "C:\Python25\Progs\blandat\myMath.py", line 9, in isPrime if x == nbr: UnboundLocalError: local variable 'x' referenced before assignment map(isPrime, range(100)) Tracebac

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread Mensanator
> >             break > > >     if x == nbr: > > >         return True > > >     else: > > >         return False > > > > >>> [isPrime(y) for y in range(11)] > > > > Traceback (most recent call last): > > >   F

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread Mensanator
;         return False > > >>>>> [isPrime(y) for y in range(11)] > > >> Traceback (most recent call last): > >>   File "", line 1, in > >>     [isPrime(y) for y in range(11)] > >>   File "C:\Python25\Progs\blandat\myMath.py", lin

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread defn noob
      return False > > > >>> [isPrime(y) for y in range(11)] > > > Traceback (most recent call last): > >   File "", line 1, in > >     [isPrime(y) for y in range(11)] > >   File "C:\Python25\Progs\blandat\myMath.py", line 9, in isPrime &

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread Mensanator
, in >     [isPrime(y) for y in range(11)] >   File "C:\Python25\Progs\blandat\myMath.py", line 9, in isPrime >     if x == nbr: > UnboundLocalError: local variable 'x' referenced before assignment > > >>> map(isPrime, range(100)) > > Traceback (mo

RE: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread Andreas Tawn
>> File "", line 1, in >> [isPrime(y) for y in range(11)] >> File "C:\Python25\Progs\blandat\myMath.py", line 9, in isPrime >> if x == nbr: >> UnboundLocalError: local variable 'x' referenced before assignment >> >

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread norseman
== nbr: return True else: return False [isPrime(y) for y in range(11)] Traceback (most recent call last): File "", line 1, in [isPrime(y) for y in range(11)] File "C:\Python25\Progs\blandat\myMath.py", line 9, in isPrime if x == nbr: Unbo

isPrime works but UnBoundLocalError when mapping on list

2008-07-15 Thread defn noob
True else: return False >>> [isPrime(y) for y in range(11)] Traceback (most recent call last): File "", line 1, in [isPrime(y) for y in range(11)] File "C:\Python25\Progs\blandat\myMath.py", line 9, in isPrime if x == nbr: UnboundLocalError:

Re: UnboundLocalError problems

2008-06-29 Thread Terry Reedy
IG_TYPE = 0 ORIG_MSG = "" def my_func2(IsEnabled): you need global ORIG_TYPE,ORIG_MSG if IsEnabled: ORIG_TYPE,ORIG_MSG = get_current() because this otherwise marks them as local. [snip] When I run it,it errors out at : set_status(ORIG_TYPE,ORIG_MSG) g

UnboundLocalError problems

2008-06-29 Thread Mr SZ
op.run() When I run it,it errors out at : set_status(ORIG_TYPE,ORIG_MSG) giving the error "UnboundLocalError: local variable 'ORIG_TYPE' referenced before assignment" .This happens Aren't ORIG_TYPE and ORIG_MSG global variables? Where am I going wrong?

Re: Error: UnboundLocalError: local variable 'PfFlag' referenced before assignment

2007-12-01 Thread [EMAIL PROTECTED]
recent call last): > > File "C:\UDR2\UDRxmlGateway.py", line 388, in > > ParseAll() > > File "C:\UDR2\UDRxmlGateway.py", line 371, in ParseAll > > if (PfFlag == 1): > > UnboundLocalError: local variable 'PfFlag' reference

Re: Error: UnboundLocalError: local variable 'PfFlag' referenced before assignment

2007-11-30 Thread Calvin
lGateway.py", line 388, in > ParseAll() > File "C:\UDR2\UDRxmlGateway.py", line 371, in ParseAll > if (PfFlag == 1): > UnboundLocalError: local variable 'PfFlag' referenced before assignment > > PfFlag gets assigned in a for loop in

Error: UnboundLocalError: local variable 'PfFlag' referenced before assignment

2007-11-30 Thread Wang, Harry
if (PfFlag == 1): UnboundLocalError: local variable 'PfFlag' referenced before assignment PfFlag gets assigned in a for loop in line 365 for i in range(PfFlagArrSize): if (PfFlagArr[i] == 1): ---> PfFlag = int(1) break else

Re: UnboundLocalError on global variable

2007-09-09 Thread GuillaumeC
> def processLogEntry(entry): # ADD THIS TO YOUR CODE global cmterID_ > >revision = int(entry.getRevision()) >commiter = str(entry.getAuthor()) >datetime = getTimeStamp(entry.getDate()) >message = str(entry.getMessage()) > >Commiter_[0] = cmterID_ //HERE's THE PROBLEM The r

Re: UnboundLocalError on global variable

2007-09-09 Thread GuillaumeC
> def processLogEntry(entry): # ADD THIS TO YOUR CODE global cmterID_ > >revision = int(entry.getRevision()) >commiter = str(entry.getAuthor()) >datetime = getTimeStamp(entry.getDate()) >message = str(entry.getMessage()) > >Commiter_[0] = cmterID_ //HERE's THE PROBLEM The r

UnboundLocalError on global variable

2007-09-09 Thread Konstantinos Pachopoulos
some vars outside the functions (global ones), but when i use them inside the functions, i get an "UnboundLocalError" error. Here's the interesting part of the code: == #imports

  1   2   >