Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread Simo Melenius
Just <[EMAIL PROTECTED]> writes: > In article <[EMAIL PROTECTED]>, > Simo Melenius <[EMAIL PROTECTED]> wrote: > > ... sys.stdout = sys.__stdout__ > Aargh, I can't believe how widespread this idiom is :-(. See my other > reply in this thread: DON'T use sys.__stdout__. Ever. It probably d

Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread JanC
Just schreef: > You should always save stdout instead of using __stdout__. It may not be > the same! You're right, especially when this code would execute in an (at programming time) unknown context. -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Prin

Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread Ron Garret
In article <[EMAIL PROTECTED]>, Just <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Simo Melenius <[EMAIL PROTECTED]> wrote: > > > I've sometimes replaced sys.stdout (and/or sys.stderr) to > > capture/redirect debugging information in existing code that has > > unwisely just "pr

Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread michele . simionato
(Not sure if my other message arrived) I am guilty of using this idiom, too. The standard library http://www.python.org/dev/doc/devel/lib/module-sys.html#l2h-396 says: """ __stdin__ __stdout__ __stderr__ These objects contain the original values of stdin, stderr and stdout at the start of the p

Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread michele . simionato
Just wrote: > In article <[EMAIL PROTECTED]>, > Simo Melenius <[EMAIL PROTECTED]> wrote: > > > I've sometimes replaced sys.stdout (and/or sys.stderr) to > > capture/redirect debugging information in existing code that has > > unwisely just "print"ed error and warning messages, instead of using >

Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread Just
In article <[EMAIL PROTECTED]>, Simo Melenius <[EMAIL PROTECTED]> wrote: > I've sometimes replaced sys.stdout (and/or sys.stderr) to > capture/redirect debugging information in existing code that has > unwisely just "print"ed error and warning messages, instead of using > sys.stderr or error logg

Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread Simo Melenius
Ron Garret <[EMAIL PROTECTED]> writes: > (with-output-to-string (s) > (let ( (*standard-output* s) ) > (call-html-generating-code) > s)) > > Is there an equivalent Python trick to capture a function call's output > as a string? I've sometimes replaced sys.stdout (and/or sys.stderr) to

Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread Just
In article <[EMAIL PROTECTED]>, JanC <[EMAIL PROTECTED]> wrote: > Something like this: > > py> import cStringIO > py> import sys > py> > py> def foo(): > ... print "test" > ... > py> f = cStringIO.StringIO() > py> sys.stdout = f > py> foo() > py> s = f.getvalue() > py> sys.stdout = sys.__std

Re: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-03 Thread JanC
Ron Garret schreef: > But this topic does bring up a legitimate question: I have a bunch of > code that generates HTML using PRINT statements. I need to convert all > this code to return strings rather than actually printing them (so I can > use the results to populate templates). In Lisp I c

Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)

2005-01-02 Thread Ron Garret
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Aahz) wrote: > In article <[EMAIL PROTECTED]>, > Roy Smith <[EMAIL PROTECTED]> wrote: > >In article <[EMAIL PROTECTED]>, > > Ron Garret <[EMAIL PROTECTED]> wrote: > >> In article <[EMAIL PROTECTED]>, > >> "Erik Bethke" <[EMAIL PROTECTED]> wrot