Redirecting Python stdout ,stderr and stdin

Serge Orlov sombDELETE at pobox.ru
Sun Nov 23 19:51:39 EST 2003


"Alexander Schmolck" <a.schmolck at gmx.net> wrote in message news:yfssmke8vl0.fsf at black132.ex.ac.uk...
> Jan Knop <nospam at nospam.yes> writes:
>
> > Hello
> >
> > I am writing a  Windows application where I need to  redirect stdin,
> > stdout and  stderr from Python.  to my application
> > Is it a simple way  of  do it  ?
>
> import sys
> sys.stdin, sys.stderr, sys.stdout = map(open, 'in.txt err.txt out.txt'.split(),
>                                               'r w w'.split())

That is why map should be deprecated asap ;)

sys.stdin = open("in.txt")
sys.stdout = open("out.txt","w")
sys.stderr = open("err.txt","w")

-- Serge






More information about the Python-list mailing list