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

2005-03-19 Thread Peter Moscatt
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


-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-03-18 Thread Diez B. Roggisch
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
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-03-18 Thread 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()



-- 
http://mail.python.org/mailman/listinfo/python-list