redirecting stderr back..

rh0dium steven.klass at gmail.com
Fri Jan 9 18:10:48 EST 2009


On Jan 9, 3:52 pm, Christian Heimes <li... at cheimes.de> wrote:
> Robert Kern schrieb:
>
>
>
> > Christian Heimes wrote:
> >> rh0dium schrieb:
> >>> Hi All,
>
> >>> Can someone tell me how to redirect stderr back to the console once
> >>> you've moved it?
>
> >> sys.stderr = sys.__stderr__
>
> >> or better:
>
> >> orig_stderr = sys.stderr
> >> try:
> >>     sys.stderr = open(...)
> >>     ...
> >> finally:
> >>     sys.stderr = orig_stderr
>
> > He's not reassigning the sys.stderr object; he's fiddling with the
> > underlying file descriptor.
>
> I know that. I wanted to show him a better way than messing around with
> file descriptors. In Python one doesn't have to (and should not) alter
> the file descriptor of a standard stream. Python always uses sys.stderr
> to write to the standard error stream.
>
> Christian

Christian - it's not python that's the problem.  Unfortunately the
stuff I'm calling (outside of python) won't play nicely unless I mess
with the FD's..





More information about the Python-list mailing list