show headersget message hdr+body for (idsubjin subjects[-showcount:if fetch all hdrs print('article % [% ](idsubj)if not listonly and input('=display?'in [' '' ']replynumtidlist connection head(idfor line in listfor prefix in showhdrsif line[:len(prefix)=prefixprint(line[: ]break if input('=show body?'in [' '' ']replynumtidlist connection body(idfor line in listprint(line[: ]print(print(connection quit()as for ftp and email toolsthe script creates an nntp object and calls its methods to fetch newsgroup information and articlesheader and body text the xhdr methodfor exampleloads selected headers from range of messages for nntp servers that require authenticationyou may also have to pass usernamea passwordand possibly reader-mode flag to the nntp call see the python library manual for more on other nntp parameters and object methods in the interest of space and timei'll omit this script' outputs here when runit connects to the server and displays each article' subject linepausing to ask whether it should fetch and show the article' header information lines (headers listed in the variable showhdrs onlyand body text we can also pass this script an explicit server namenewsgroupand display count on the command line to apply it in different ways with little more workwe could turn this script into full-blown news interface for instancenew articles could be posted from within python script with code of this form (assuming the local file already contains proper nntp header lines)to postsay this (but only if you really want to post!connection nntp(servernamelocalfile open('filename'file has proper headers connection post(localfilesend text to newsgroup connection quit(we might also add tkinter-based gui frontend to this script to make it more usablebut we'll leave such an extension on the suggested exercise heap (see also the pymailgui interface' suggested extensions at the end of the next -email and news messages have similar structurenntpaccessing newsgroups