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
On 06/24/2013 04:12 PM, John Gordon wrote: In pablobarhamal...@gmail.com writes: isWhite = True def change(event): if event.x > x1 and event.x < x2 and event.y > y1 and event.y < y2: if isWhite: w.itemconfig(rect, fill="blue") isWhite = False

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
In pablobarhamal...@gmail.com writes: > isWhite = True > > def change(event): > if event.x > x1 and event.x < x2 and event.y > y1 and event.y < y2: > if isWhite: > w.itemconfig(rect, fill="blue") > isWhite = False > else: > w.itemc

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

2013-06-24 Thread Antoon Pardon
Op 24-06-13 21:47, pablobarhamal...@gmail.com schreef: Hi there! I'm quite new to programming, even newer in python (this is actually the first thing I try on it), and every other topic I've seen on forums about my problem doesn't seem to help. So, the following lines are intended to draw a wh

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

2013-06-24 Thread Peter Otten
pablobarhamal...@gmail.com wrote: > Hi there! I'm quite new to programming, even newer in python (this is > actually the first thing I try on it), and every other topic I've seen on > forums about my problem doesn't seem to help. > > So, the following lines are intended to draw a white square (wh

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
Hi there! I'm quite new to programming, even newer in python (this is actually the first thing I try on it), and every other topic I've seen on forums about my problem doesn't seem to help. So, the following lines are intended to draw a white square (which it does), turn it to blue when you cl

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
Peter Otten wrote: > Chris Rebert wrote: [...] > > The only global variable defined in mkTable.py is the "mkTable" > > function (partly since you don't import anything). So the reference to > > the global variable "canvas" on the right-hand side of this expression > > is completely undefined, resul

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Peter Otten
Chris Rebert wrote: > On Tue, Jun 8, 2010 at 2:00 AM, ch1zra wrote: >> On Jun 8, 10:29 am, Richard Thomas wrote: >>> On Jun 8, 9:03 am, ch1zra wrote: >>> > I have following code : >>> >>> > import os, time, re, pyodbc, Image, sys >>> > from datetime import datetime, date, time >>> > from report

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
On Jun 8, 10:59 am, Bryan wrote: > ch1zra wrote: > > I have following code : > > > 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 > > fro

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Chris Rebert
On Tue, Jun 8, 2010 at 2:00 AM, ch1zra wrote: > On Jun 8, 10:29 am, Richard Thomas wrote: >> On Jun 8, 9:03 am, ch1zra wrote: >> > I have following code : >> >> > import os, time, re, pyodbc, Image, sys >> > from datetime import datetime, date, time >> > from reportlab.lib.pagesizes import A4 >>

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
On Jun 8, 10:29 am, Richard Thomas wrote: > On Jun 8, 9:03 am, ch1zra wrote: > > > > > > > I have following code : > > > 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

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Bryan
ch1zra wrote: > I have following code : > > 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 repor

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Richard Thomas
On Jun 8, 9:03 am, ch1zra wrote: > I have following code : > > 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 pdf

UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
I have following code : 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.ttfonts import TTF

Re: local variable referenced before assignment

2010-04-06 Thread Steven D'Aprano
On Mon, 05 Apr 2010 10:08:51 -0700, John Nagle wrote: > Alf P. Steinbach wrote: > >> Best is however to recognize that you have some state (your variable) >> and some operations on that state (your callback), and that that is >> what objects are all about. I.e. wrap your logic in a class. Then >>

Re: local variable referenced before assignment

2010-04-05 Thread Stephen Hansen
On 2010-04-05 10:08:51 -0700, John Nagle said: Yes. Functions with persistent state are generally a bad idea. Unfortunately, the "signal" module requires a callback parameter which is a plain function. So you have to send it a function, closure, or lambda. Here, it's being sent a clos

Re: local variable referenced before assignment

2010-04-05 Thread Robert Kern
On 2010-04-05 12:08 PM, John Nagle wrote: Alf P. Steinbach wrote: Best is however to recognize that you have some state (your variable) and some operations on that state (your callback), and that that is what objects are all about. I.e. wrap your logic in a class. Then 'lastModifiedTime' become

Re: local variable referenced before assignment

2010-04-05 Thread John Nagle
Alf P. Steinbach wrote: Best is however to recognize that you have some state (your variable) and some operations on that state (your callback), and that that is what objects are all about. I.e. wrap your logic in a class. Then 'lastModifiedTime' becomes an instance attribute, and 'handler' be

Re: local variable referenced before assignment

2010-04-04 Thread Alf P. Steinbach
* Stephen Hansen: On 2010-04-04 15:22:48 -0700, Alf P. Steinbach said: * johngilbrough: I cannot make sense of what's happening here ... I'm getting the following error: (1) At least in Py3 you can declare the variable as 'global', like this: global lastModifiedTime within the function

Re: local variable referenced before assignment

2010-04-04 Thread Stephen Hansen
On 2010-04-04 15:22:48 -0700, Alf P. Steinbach said: * johngilbrough: I cannot make sense of what's happening here ... I'm getting the following error: (1) At least in Py3 you can declare the variable as 'global', like this: global lastModifiedTime within the function. Actually, what

Re: local variable referenced before assignment

2010-04-04 Thread Alf P. Steinbach
* johngilbrough: I cannot make sense of what's happening here ... I'm getting the following error: initializing last modified time /home/john/Dropbox/Projects/python/scripts/src 29 referencing last modified time /home/john/Dropbox/Projects/python/scripts/src 29 referencing last modified time Tr

local variable referenced before assignment

2010-04-04 Thread johngilbrough
I cannot make sense of what's happening here ... I'm getting the following error: initializing last modified time /home/john/Dropbox/Projects/python/scripts/src 29 referencing last modified time /home/john/Dropbox/Projects/python/scripts/src 29 referencing last modified time Traceback (most recen

Re: n00b confusion re: local variable referenced before assignment error

2009-06-19 Thread Dave Angel
Wells Oliver wrote: Writing a class which essentially spiders a site and saves the files locally. On a URLError exception, it sleeps for a second and tries again (on 404 it just moves on). The relevant bit of code, including the offending method: class Handler(threading.Thread): def __in

Re: n00b confusion re: local variable referenced before assignment error

2009-06-19 Thread Mike Kazantsev
On Fri, 19 Jun 2009 11:16:38 -0500 Wells Oliver wrote: > def save(self, uri, location): > try: > handler = urllib2.urlopen(uri) > except urllib2.HTTPError, e: > if e.code == 404: >

Re: n00b confusion re: local variable referenced before assignment error

2009-06-19 Thread Diez B. Roggisch
Wells Oliver schrieb: Writing a class which essentially spiders a site and saves the files locally. On a URLError exception, it sleeps for a second and tries again (on 404 it just moves on). The relevant bit of code, including the offending method: class Handler(threading.Thread): def

Re: n00b confusion re: local variable referenced before assignment error

2009-06-19 Thread Falcolas
On Jun 19, 10:16 am, Wells Oliver wrote: > Writing a class which essentially spiders a site and saves the files > locally. On a URLError exception, it sleeps for a second and tries again (on > 404 it just moves on). The relevant bit of code, including the offending > method: > > [snip] > > But wha

n00b confusion re: local variable referenced before assignment error

2009-06-19 Thread Wells Oliver
Writing a class which essentially spiders a site and saves the files locally. On a URLError exception, it sleeps for a second and tries again (on 404 it just moves on). The relevant bit of code, including the offending method: class Handler(threading.Thread): def __init__(self, url):

Re: local variable referenced before assignment

2007-10-25 Thread Pete Bartonly
Pete Bartonly wrote: > > Quick question, probably quite a simple matter. Take the follow start of > a method: > > > def review(filesNeedingReview): > > for item in filesNeedingReview: > (tightestOwner, logMsg) = item > > if (logMsg != None): > for logInfo in lo

Re: local variable referenced before assignment

2007-10-25 Thread Pete Bartonly
Peter Otten wrote: > Pete Bartonly wrote: > >> Quick question, probably quite a simple matter. Take the follow start of >> a method: >> >> >> def review(filesNeedingReview): >> >> for item in filesNeedingReview: >> (tightestOwner, logMsg) = item >> >> if (logMsg != None): >

Re: local variable referenced before assignment

2007-10-25 Thread Pete Bartonly
A.T.Hofkamp wrote: > On 2007-10-25, Pete Bartonly <[EMAIL PROTECTED]> wrote: >> Quick question, probably quite a simple matter. Take the follow start of >> a method: > With respect to compactness and style, you can move your multi-assignment > statement in the for loop, as in [snip] Btw, thanks

Re: local variable referenced before assignment

2007-10-25 Thread Pete Bartonly
A.T.Hofkamp wrote: > On 2007-10-25, Pete Bartonly <[EMAIL PROTECTED]> wrote: >> Quick question, probably quite a simple matter. Take the follow start of >> a method: >> >> >> def review(filesNeedingReview): >> >> for item in filesNeedingReview: >> (tightestOwner, logMsg) = item >> >>

Re: local variable referenced before assignment

2007-10-25 Thread A.T.Hofkamp
On 2007-10-25, Tim Williams <[EMAIL PROTECTED]> wrote: > On 25/10/2007, A.T.Hofkamp <[EMAIL PROTECTED]> wrote: >> On 2007-10-25, Pete Bartonly <[EMAIL PROTECTED]> wrote: >> > >> Also, brackets around conditions (in the if) are not needed, and comparing >> against None is usually done with 'is' or '

Re: local variable referenced before assignment

2007-10-25 Thread Tim Williams
On 25/10/2007, A.T.Hofkamp <[EMAIL PROTECTED]> wrote: > On 2007-10-25, Pete Bartonly <[EMAIL PROTECTED]> wrote: > > > Also, brackets around conditions (in the if) are not needed, and comparing > against None is usually done with 'is' or 'is not' instead of '==' or '!='. > The result is then > > if

Re: local variable referenced before assignment

2007-10-25 Thread Arnaud Delobelle
On Oct 25, 10:02 am, Pete Bartonly <[EMAIL PROTECTED]> wrote: > Quick question, probably quite a simple matter. Take the follow start of > a method: > > def review(filesNeedingReview): > > for item in filesNeedingReview: > (tightestOwner, logMsg) = item > > if (logMsg != None

Re: local variable referenced before assignment

2007-10-25 Thread Peter Otten
Pete Bartonly wrote: > Quick question, probably quite a simple matter. Take the follow start of > a method: > > > def review(filesNeedingReview): > > for item in filesNeedingReview: > (tightestOwner, logMsg) = item > > if (logMsg != None): > for logInfo in

Re: local variable referenced before assignment

2007-10-25 Thread A.T.Hofkamp
On 2007-10-25, Pete Bartonly <[EMAIL PROTECTED]> wrote: > > Quick question, probably quite a simple matter. Take the follow start of > a method: > > > def review(filesNeedingReview): > > for item in filesNeedingReview: > (tightestOwner, logMsg) = item > > if (logMsg != None)

local variable referenced before assignment

2007-10-25 Thread Pete Bartonly
Quick question, probably quite a simple matter. Take the follow start of a method: def review(filesNeedingReview): for item in filesNeedingReview: (tightestOwner, logMsg) = item if (logMsg != None): for logInfo in logMsg.changed_paths: This generates the