Making the Zen of Python more useful

Andrew Henshaw andrew.henshaw at gtri.gatech.edu
Fri Apr 2 10:40:28 EST 2004


In article <-5ydnTEmxfuZHvDdRVn-iQ at powergate.ca>, peter at engcorp.com says...
>
>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

Hey, that's very slick!  But ... (starting to feel like a whiner), my main 
problem was with the automatic printing of the text upon import.  Obviously, 
that functionality needs to remain.  It would just be nice if there was 
some clean way of (sometimes) using the module without it.


Thanks again!

-- 
Andy




More information about the Python-list mailing list