Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > HELP:UnboundLocalError: local variable '_nntp' referenced before assignment

Reply
Thread Tools

HELP:UnboundLocalError: local variable '_nntp' referenced before assignment

 
 
Peter Moscatt
Guest
Posts: n/a
 
      03-18-2005
Hi all,

I am in the process of writing an app that will handle news feeds and
therefore using the 'nntplib'

When I issue the connect command all goes will but when I issue the 'quit()'
command I get the following error message:


Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.3/lib-tk/Tkinter.py", line 1345, in __call__
return self.func(*args)
File "./pnews.py", line 26, in callconnect
_nntp.quit()
UnboundLocalError: local variable '_nntp' referenced before assignment


The code below illustrates how I'm using the code. Can anyone help me out
in getting this right.

Pete


def callconnect():
if b["text"]=="Connect":
_nntp =
nntplib.NNTP(_global.servername,int(_global.portnu mber),_global.userid,_global.userpassword)
if(_nntp):
b["text"]="Disconnect"

elif b["text"]=="Disconnect":
_nntp.quit()



 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      03-18-2005
Peter Moscatt wrote:
> UnboundLocalError: local variable '_nntp' referenced before assignment


This pretty much says what your problem is: you haven't a variable called
_nntp

> def callconnect():
> if b["text"]=="Connect":
> _nntp =
>

nntplib.NNTP(_global.servername,int(_global.portnu mber),_global.userid,_global.userpassword)
> if(_nntp):
> b["text"]="Disconnect"
>
> elif b["text"]=="Disconnect":
> _nntp.quit()


And here we see why: In the Disconnect-case, where is that _nntp supposed to
come from? I'm not sure what you want here, as you seem to rely on global
variables very much, but to me the whole elif-block is bogus. You
unecessarily communicate over b['text']

Do it like this:

def callconnect():
********if*b["text"]=="Connect":
****************_nntp*=
nntplib.NNTP(_global.servername,int(_global.portnu mber),_global.userid,_global.userpassword)
****************if(_nntp):
****************_nntp.quit()


--
Regards,

Diez B. Roggisch
 
Reply With Quote
 
 
 
 
Peter Moscatt
Guest
Posts: n/a
 
      03-19-2005
Diez B. Roggisch wrote:

> Peter Moscatt wrote:
>> UnboundLocalError: local variable '_nntp' referenced before assignment

>
> This pretty much says what your problem is: you haven't a variable called
> _nntp
>
>> def callconnect():
>> if b["text"]=="Connect":
>> _nntp =
>>

>

nntplib.NNTP(_global.servername,int(_global.portnu mber),_global.userid,_global.userpassword)
>> if(_nntp):
>> b["text"]="Disconnect"
>>
>> elif b["text"]=="Disconnect":
>> _nntp.quit()

>
> And here we see why: In the Disconnect-case, where is that _nntp supposed
> to come from? I'm not sure what you want here, as you seem to rely on
> global variables very much, but to me the whole elif-block is bogus. You
> unecessarily communicate over b['text']
>
> Do it like this:
>
> def callconnect():
> if*b["text"]=="Connect":
> _nntp*=
>

nntplib.NNTP(_global.servername,int(_global.portnu mber),_global.userid,_global.userpassword)
> if(_nntp):
> _nntp.quit()
>
>


G'Day Diez,

Thanks mate.... yes, that did the trick. I guess why I am using those
globals is because I really need them to be seen by other modules.

Thanks again for the help.

Pete


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UnboundLocalError: local variable referenced before assignment ch1zra Python 9 06-08-2010 06:59 PM
local variable referenced before assignment johngilbrough Python 5 04-06-2010 07:48 AM
UnboundLocalError: local variable '_[1]' referenced before assignment Gabriel Rossetti Python 3 12-09-2009 02:48 PM
local variable referenced before assignment Pete Bartonly Python 10 10-25-2007 05:08 PM
UnboundLocalError: local variable 'colorIndex' referenced silverburgh.meryl@gmail.com Python 2 02-26-2006 09:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57