stdin, stdout, redmon

John Machin sjmachin at lexicon.net
Tue Jan 22 05:02:19 EST 2008


On Jan 22, 8:42 pm, Bernard Desnoues <bernard.desno... at univ-paris1.fr>
wrote:
> Hello,
>
> I checked under linux and it works :
> text.txt :
> "first line of the text file
> second line of the text file"
>
> test.py :
> "import sys
> a = sys.stdin.readlines()
> x = ''.join(a)
> x = x.upper()
> sys.stdout.write(x)"
>
>  >cat text.txt | python test.py
>
> But I reinstalled Python 2.5 under Windows XP and it doesn't work
> anyway. Can you confirm that your script works with Win XP and Python 2.5 ?
>
> Regards
>
> Rolf van de Krol a écrit :
>
> > I don't know what you did with your Python installation, but for me this
> > works perfectly.
>
> > test3.py contains:
> > <code>
> > import sys
>
> > print sys.stdin.readlines()
> > </code>
>
> > test.txt contains:
> > <code>
> > Testline1
> > Testline2
> > </code>
>
> > Output of 'python test3.py < test.txt' is:
> > <code>
> > ['Testline1\n', 'Testline2']
> > </code>
>
> > Just plain simple and just works.
>
> > Rolf
>
> > Bernard Desnoues wrote:
> >> Rolf van de Krol a écrit :
>
> >>> According to various tutorials this should work.
>
> >>> <code>
> >>> |import sys
> >>> data = sys.stdin.readlines()
> >>> print "Counted", len(data), "lines."|
> >>> </code>
>
> >>> Please use google before asking such questions. This was found with
> >>> only one search for the terms 'python read stdin'
>
> >>> Rolf
>
> >>> Bernard Desnoues wrote:
>
> >>>> Hi,
>
> >>>> 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
> >>>> sys.stdout.write(data)"
>
> >>>> 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
> >>>> Librarian
> >>>> 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

Excuse me, gentlemen, may I be your referee *before* you resort to
pistols at dawn?

===== IDLE =====
IDLE 1.2.1
>>> import sys
>>> sys.stdin.readlines

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    sys.stdin.readlines
AttributeError: readlines
>>>

===== Command Prompt =====
C:\junk>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdin.readlines
<built-in method readlines of file object at 0x00B1F020>
>>>

HTH,
John



More information about the Python-list mailing list