f



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

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.portnumber),_global.userid,_global.userpassword)
                if(_nntp):
                        b["text"]="Disconnect"
                        
        elif b["text"]=="Disconnect":
                _nntp.quit()
                


0
pgmoscatt1 (30)
3/18/2005 11:07:39 AM
comp.lang.python 77058 articles. 3 followers. Post Follow

2 Replies
472 Views

Similar Articles

[PageSpeed] 15

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()


-- 
Regards,

Diez B. Roggisch
0
deetsNOSPAM (601)
3/18/2005 11:24:47 AM
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


0
pgmoscatt1 (30)
3/19/2005 8:37:16 AM
Reply: