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

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)