stdin, stdout, redmon
Rolf van de Krol
python at rolfvandekrol.nl
Mon Jan 21 15:52:59 CET 2008
I don't know what you did with your Python installation, but for me this
Output of 'python test3.py < test.txt' is:
Just plain simple and just works.
Bernard Desnoues wrote:
> Rolf van de Krol a écrit :
>> According to various tutorials this should work.
>> |import sys
>> data = sys.stdin.readlines()
>> print "Counted", len(data), "lines."|
>> Please use google before asking such questions. This was found with only
>> one search for the terms 'python read stdin'
>> Bernard Desnoues wrote:
>>> I've got a problem with the use of Redmon (redirection port monitor).
>>> I intend to develop a virtual printer so that I can modify data sent
>>> to the printer.
>>> Redmon send the data flow to the standard input and lauchs the Python
>>> program which send modified data to the standard output (Windows XP
>>> and Python 2.5 context).
>>> I can manipulate the standard output.
>>> "import sys
>>> it works.
>>> But how to manipulate standard input so that I can store data in a
>>> string or in an object file ? There's no "read" method.
>>> "a = sys.stdin.read()" doesn't work.
>>> "f = open(sys.stdin)" doesn't work.
>>> I don't find anything in the documentation. How to do that ?
>>> Thanks in advance.
>>> Bernard Desnoues
>>> Bibliothèque de géographie - Sorbonne
> Hello Rolf,
> I know this code because I have search a solution !
> Your google code doesn't work ! No attribute "readlines".
> >>> import sys
> >>> data = sys.stdin.readlines()
> Traceback (most recent call last):
> File "<pyshell#1>", line 1, in <module>
> data = sys.stdin.readlines()
> AttributeError: readlines
More information about the Python-list