[Baypiggies] history of import this

Keith Dart keith at dartworks.biz
Fri Jun 11 04:01:34 CEST 2010

=== On Thu, 06/10, akleider at sonic.net wrote: ===
> What syntax would one use to capture the string that gets printed
> when one
> >>> import this  
> ????


This also works:


import sys

from StringIO import StringIO

buf = StringIO()
sys.stdout = buf

import this

s = buf.getvalue()

sys.stdout = sys.__stdout__

print s

# The string 's' now has the text. 


This method does not require a subprocess or knowledge of the this.py
internals. However, the first suggestion is probably best since the
source is easily inspected. :-)

-- Keith Dart

-- --------------------
Keith Dart
<keith at dartworks.biz>
python -m this

More information about the Baypiggies mailing list