Printing with raw_input

Joan Miller peloko45 at gmail.com
Mon Feb 15 12:40:11 CET 2010


On 15 feb, 10:11, Peter Otten <__pete... at web.de> wrote:
> Joan Miller wrote:
> > Does `raw_input` uses internally `sys.stdout.write`?
>
> You can test this yourself without reading the C source:
>
> Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> import sys
> >>> class A:
>
> ...     def write(self, s):
> ...             sys.__stdout__.write(s.upper())
> ...>>> sys.stdout = A()
> >>> print "yadda"
> YADDA
> >>> raw_input("foo")
>
> FOObar
> 'BAR'
>
> Peter

It was to display the output inside a GUI app. overriding
`sys.stdout`. And as `print` also uses internally `sys.stdout.write`
then can be used `print` the shell script and get the output too in
the GUI, cann't it?



More information about the Python-list mailing list