Question about NNTPLib

  • Thread starter Anthony Papillion
  • Start date
A

Anthony Papillion

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

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
 
T

Tim Wintle

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

While the loop will indeed LOOP through all of the items, the print
statement generates unprintable character (they look like [] in the
terminal window.

"[]" is the way python prints an empty list.

I don't know NNTPLib, but I'm guessing you don't want to be throwing
away the subject variable, so you either want

for subject in items:
print subject

or

for subject in items:
resp, sub = server.xhdr("subject", first, last)
print sub

- the second will do the same as your current code, I don't know how
NNTPLib returns the subject or what the list it's returning represents.
 
A

Anthony Papillion

Hi Tim,

Tried both and neither works. While I really believe it's simply the
wrong code, I'm wondering if my news server might be throwing
something invalid into the header or not conforming to RFC standards.
Thanks for taking a shot at this anyway though.

Anyone have any other thoughts on why this isn't working?
 
T

Thomas Jollans

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
 

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,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top