sys.stdin.read question

Caleb Hattingh caleb1 at telkomsa.net
Thu Dec 9 03:34:31 CET 2004


I don't have much experience with popen3.  I do know that IDLE  
(interactive interpreter) does something to sys.stdin, and that is  
probably the problem you are seeing.  Try your commands through the python  
interactive interpreter started from a shell (DOS or Bash), see if it  
still happens.

thx
Caleb


On Tue, 7 Dec 2004 23:16:50 +0100, Lars Tengnagel <lars at xvet.dk> wrote:

> Hej Caleb and others
>
> I've been strugling with the same problem where i try to use popen3 to  
> run a
> program. If I use a piped commandline
> the program can read the file without problems but in the IDLE and with
> popen it comes with an error.
> I haven't been able to read the stdin either so the problem so far is
> unsolved for my point.
> But the newline command would explain my problems with the program.
> Can it be a problem under windows since I'm using XP and the winpython
>
> Hopefully Lars
>
> "Caleb Hattingh" <caleb1 at telkomsa.net> skrev i en meddelelse
> news:opsin95ryq1js0xs at news.telkomsa.net...
>> It runs properly in a shell (bash), but on another matter:
>>
>> '>>> r=sys.stdin.read(1)
>> g
>> '>>> r
>> 'g'
>> '>>> r=sys.stdin.read(5)
>> 1234567890
>> '>>> r
>> '\n1234'
>> '>>>
>>
>> What exactly happened to my 1234567890?  I understand that I am only
>> taking 5 characters, but where does the newline (\n) come from?  Is  
>> that a
>> remnant from when I terminated the previous 'g' input?
>>
>> Thanks
>> Caleb
>>
>>
>> On Tue, 07 Dec 2004 23:36:56 -0500, Caleb Hattingh <caleb1 at telkomsa.net>
>> wrote:
>>
>>> Hi
>>>
>>> You are probably typing this within IDLE.  Try it after starting python
>>> in a shell like DOS or Bash.  Should work then (works for me, and I  
>>> also
>>> get the AttributeError in IDLE.
>>>
>>> Thanks
>>> Caleb
>>>
>>> On Tue, 07 Dec 2004 21:15:51 GMT, It's me <itsme at yahoo.com> wrote:
>>>
>>>> Why do I get an "AttributeError: read" message when I do:
>>>>
>>>>     import sys
>>>>     r=sys.stdin.read()
>>>>
>>>> ??
>>>>
>>>> I've tried:
>>>>
>>>>     r=sys.stdin.read(80)
>>>>     r=sys.stdin.read(1)
>>>>
>>>> same error message.
>>>>
>>>> I couldn't find any reference to this function in my Python book (they
>>>> have
>>>> the stdout but not in).
>>>>
>>>> Some sample code I saw uses this function in the same manner I am and
>>>> so I
>>>> am assuming this is the correct syntax?
>>>>
>>>> Or is this a bug in Python 2.4?
>>>>
>>>> --
>>>> It's me
>>>>
>>>>
>>>
>>
>
>




More information about the Python-list mailing list