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

Peter Moscatt pgmoscatt at optushome.com.au
Sat Mar 19 03:37:16 EST 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.portnumber),_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.portnumber),_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





More information about the Python-list mailing list