vagueish questions on use of file/string objects

A Meowbot meowbot at meowing.net
Tue Jan 29 02:54:22 EST 2002


kkeller at speakeasy.net (Keith Keller) wrote:

> Being stdin, though, it's not really possible to manipulate well, so
> I've been putting the post text into a string.
>
> However, the nntplib module demands a file object for its post method.

This is the option you want:

> ==Create a fake file object that's not on disk, and pass it to the
> nntplib post method.  I looked all over the place for docs on how to do
> this, but couldn't find anything helpful.  Either I'm clueless, the
> docs are buried, or they don't exist.

Nah, you just need to know what to look for.  With a seemingly
infinite standard library, that alone can be a challenge.

import nntplib, cStringIO
swerver = nntplib.NNTP("news.example.net")
F = cStringIO.StringIO(my_string_which_is_mine_and_I_want_to_be_posting)
swerver.post(F)

If you're doing this sort of thing, you'll probably be messing with
headers and stuff.  Check out the email module family in Python 2.2
for a really, really nice way of dealing with 'em.



More information about the Python-list mailing list