vagueish questions on use of file/string objects

Keith Keller kkeller at speakeasy.net
Tue Jan 29 00:36:37 EST 2002


Okay, bear with me here.

I've just started coding a little Python, and I ran into a bit of
a snag.  I would like to generate a news posting from sys.stdin, but
only after doing some manipulations on it, mostly with the headers.
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.
So, I have five options:

==Open a temp file, put the post there, then use it with post.
This works, of course, but then I'm accessing the disk, which doesn't
strike me as being too elegant, since I can do everything I need to
do in memory, and don't need disk storage.

==Subclass NNTP, and create a new method that accepts a string instead
of a file (or override the post method which can detect whether it's
being passed a file object or string object and act accordingly).  I've
done this, and it works (well, except for error checking the string,
but there's not an immense amount of error checking in nntplib's method,
anyway).  But...well, it seems odd.

==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.

I suppose the vague question is: What would be the ''standard'' Python
way to handle my dilemma?  Is there another way I'm overlooking?

--keith

-- 
kkeller at speakeasy.net
public key:  http://wombat.san-francisco.ca.us/kkeller/public_key
alt.os.linux.slackware FAQ:  http://wombat.san-francisco.ca.us/perl/fom




More information about the Python-list mailing list