Making the Zen of Python more useful

Peter Hansen peter at engcorp.com
Fri Apr 2 10:13:07 EST 2004


Andrew Henshaw wrote:

> In article <BPWdnVtfl7ma5PDdRVn-sw at powergate.ca>, peter at engcorp.com says...
>>I'm not sure why you had to do quite all that.  The following is 
>>sufficient, and you don't need a custom ROT-13 thingie:
>>
>>>>>import StringIO, sys
>>>>>s = StringIO.StringIO()
>>>>>sys.stdout = s
>>>>>import this
>>>>>sys.stdout = sys.__stdout__
>>>>>s.getvalue()
>>
>>"The Zen of Python, by Tim Peters\n\nBeautiful is ...
> 
> Much better.  Still pretty awkward for the purpose I described.  Perhaps, the 
> best solution, overall.

Okay then, how about this one?  :-)

 >>> import this
The Zen of Python, by Tim Peters\n\nBeautiful is ...
 >>> this.s.decode('rot-13')
u"The Zen of Python, by Tim Peters\n\nBeautiful is ...

-Peter



More information about the Python-list mailing list