reusing sys.stdin?

Chris Gonnerman chris.gonnerman at usa.net
Thu Apr 12 22:54:48 EDT 2001


The rfc822 module assumes that everything after the first blank line
is message body, and it does in fact "consume" it.  The file object
you give when instantiating the class winds up in the instance
variable fp.

In other words, your variable named "message_headers" actually 
"contains" the entire message, not just the headers.

If you want blocks of header-like data without bodies, look at my
QChunk.py module; my key-data pairs are not completely RFC 822
compliant, but the code might give you some ideas.

All my projects (including QChunk.py) are at:

    http://newcenturycomputers.net/projects

On the other hand, if you are processing a mailbox, look into the
mailbox module.  It handles multiple messages in a single file or
file-like object.

----- Original Message ----- 
From: "Graham Guttocks" <graham_guttocks at yahoo.co.nz>
Subject: reusing sys.stdin?


> Greetings,
> 
> Something I don't understand.  In my program I need to access
> sys.stdin from two different functions in the following manner:
> 
>    import rfc822,sys
>    message_headers = rfc822.Message(sys.stdin)
> 
> The problem is that after the first Message instance is created,
> sys.stdin seems to be absorbed so that it is no longer around for the
> second call to rfc822.Message().  Why is this, and is there a way to
> keep sys.stdin for disappearing so I can use it a second time?
> 
> Regards,
> Graham






More information about the Python-list mailing list