Question about NNTPLib

Thomas Jollans thomas at jollans.com
Tue Jun 8 17:46:21 EDT 2010


On 06/08/2010 05:24 PM, Anthony Papillion wrote:
> I'm new to NNTPLib (and Python) and I'm experiencing some behavior I
> can't understand. I'm writing a program to analyze newsgroup subject
> which will then produce statistics on topics discussed. For my
> example, I'm using this group (comp.lang.python) and trying to simply
> print out all of the subjects listed in the group.
>
> This is the code I'm using:
>
> resp, count, first, last, name = server.group('comp.lang.python')
>     resp, items = server.xover(first, last)
>
>     for subject in items:
>         resp, subject = server.xhdr('subject', first, last)
>         print subject
>   
I just had a quick look at the documentation. It looks like you should
re-read it.
http://docs.python.org/py3k/library/nntplib.html#nntplib.NNTP.xhdr

xhdr returns a whole list. It looks like you'd need something like

resp, subjects = server.xhdr('subject', '{0}-{1}'.format(first, last))
for sub in subjects:
    print (sub)

you should also have another close look at the documentation of xover:
http://docs.python.org/py3k/library/nntplib.html#nntplib.NNTP.xover

and then maybe write something like this:

resp, items = server.xover(first, last)
subjects = (info[1] for info in items)
for s in subjects:
    print (s)

Have fun,
Thomas

PS: my untested code here was sketched up with Python 3.x in mind. You
might have to change one or two things for it to work on older versions.

> While the loop will indeed LOOP through all of the items, the print
> statement generates unprintable character (they look like [] in the
> terminal window.
>
> What am I doing wrong? I've looked at the doc and it looks like this
> is how I'd call it. Am I missing something?
>
> Thanks!
> Anthony
>   




More information about the Python-list mailing list