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

P

Peter Moscatt

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

Diez B. Roggisch

Peter said:
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()
 
P

Peter Moscatt

Diez said:
Peter said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top