reusing sys.stdin?

Ixokai news at myNOSPAM.org
Fri Apr 13 00:25:05 EDT 2001


Hello,
    sys.stdin and sys.stdout are basically buffers; they're spaces of data
that you havn't gotten around to using yet. So after you do consume them,
they are indeed gone.

    You can save what is in them at any one point in time by just reading it
into a temporary variable for accessing later; the below will likely work
fine for you:

import rfc822, sys, cStringIO

stdin = cStringIO.StringIO(sys.stdin.read())

message_headers = rfc822.Message(stdin)

--Ix
(replace 'NOSPAM' with 'myseraph' to respond)
"Graham Guttocks" <graham_guttocks at yahoo.co.nz> wrote in message
news:mailman.987121758.7658.python-list at python.org...
> 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
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list