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

Diez B. Roggisch deetsNOSPAM at web.de
Fri Mar 18 06:24:47 EST 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.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



More information about the Python-list mailing list