By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

sys.stdin.read question

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On 2004-12-07, It's me <it***@yahoo.com> wrote:
Why do I get an "AttributeError: read" message when I do:

import sys
r=sys.stdin.read()
Dunno. Works fine for me under 2.3.4, and according to the
docs, should work under 2.4.

What do you get when you do this:

import sys
type(sys.stdin)
dir(sys.stdin)
Some sample code I saw uses this function in the same manner I
am and so I am assuming this is the correct syntax?
Should be.
Or is this a bug in Python 2.4?


That would be a little hard to believe.

--
Grant Edwards grante Yow! PEGGY FLEMMING is
at stealing BASKET BALLS to
visi.com feed the babies in VERMONT.
Jul 18 '05 #2

P: n/a
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 <it***@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


Jul 18 '05 #3

P: n/a
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 <ca****@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 <it***@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


Jul 18 '05 #4

P: n/a

"Grant Edwards" <gr****@visi.com> wrote in message
news:41**********************@visi.com...
On 2004-12-07, It's me <it***@yahoo.com> wrote:
Why do I get an "AttributeError: read" message when I do:

import sys
r=sys.stdin.read()
Dunno. Works fine for me under 2.3.4, and according to the
docs, should work under 2.4.

What do you get when you do this:

import sys


Done that.
type(sys.stdin)
I get:

<type 'instance'>
dir(sys.stdin)
I get:

['_RPCProxy__attributes', '_RPCProxy__getattributes',
'_RPCProxy__getmethods', '_RPCProxy__methods', '__doc__', '__getattr__',
'__init__', '__module__', 'encoding', 'oid', 'sockio']
Some sample code I saw uses this function in the same manner I
am and so I am assuming this is the correct syntax?


Should be.
Or is this a bug in Python 2.4?


That would be a little hard to believe.


Well, here's a copy from the Python Shell output:
print sys.stdin.read(5)
Traceback (most recent call last):
File "<pyshell#26>", line 1, in -toplevel-
print sys.stdin.read(5)
AttributeError: read


????????
Jul 18 '05 #5

P: n/a
On 2004-12-07, It's me <it***@yahoo.com> wrote:
Dunno. Works fine for me under 2.3.4, and according to the
docs, should work under 2.4.

What do you get when you do this:

import sys
Done that.
type(sys.stdin)


I get:

<type 'instance'>
dir(sys.stdin)


I get:

['_RPCProxy__attributes', '_RPCProxy__getattributes',
'_RPCProxy__getmethods', '_RPCProxy__methods', '__doc__', '__getattr__',
'__init__', '__module__', 'encoding', 'oid', 'sockio']

????????


As somebody else already suggested, you must be running your
program inside some sort of IDE that replaces sys.stdin with
some other object that doesn't have a read() method. Try
running the program from a shell prompt.
--
Grant Edwards grante Yow! Someone in DAYTON,
at Ohio is selling USED
visi.com CARPETS to a SERBO-CROATIAN
Jul 18 '05 #6

P: n/a
On 2004-12-08, Caleb Hattingh <ca****@telkomsa.net> wrote:
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?


Exactly.

The input stream consisted of 'g\n1234567890\n'

--
Grant Edwards grante Yow! My EARS are GONE!!
at
visi.com
Jul 18 '05 #7

P: n/a
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" <ca****@telkomsa.net> skrev i en meddelelse
news:op**************@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 <ca****@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 <it***@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

Jul 18 '05 #8

P: n/a
Yes, if I run the script from the command prompt, it works. I was running
it inside the Python IDE.

Thanks,

--
It's me
"Grant Edwards" <gr****@visi.com> wrote in message
news:41***********************@visi.com...
On 2004-12-07, It's me <it***@yahoo.com> wrote:
Dunno. Works fine for me under 2.3.4, and according to the
docs, should work under 2.4.

What do you get when you do this:

import sys
Done that.
type(sys.stdin)


I get:

<type 'instance'>
dir(sys.stdin)


I get:

['_RPCProxy__attributes', '_RPCProxy__getattributes',
'_RPCProxy__getmethods', '_RPCProxy__methods', '__doc__', '__getattr__',
'__init__', '__module__', 'encoding', 'oid', 'sockio']

????????


As somebody else already suggested, you must be running your
program inside some sort of IDE that replaces sys.stdin with
some other object that doesn't have a read() method. Try
running the program from a shell prompt.
--
Grant Edwards grante Yow! Someone in

DAYTON, at Ohio is selling USED
visi.com CARPETS to a

SERBO-CROATIAN
Jul 18 '05 #9

P: n/a
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 <la**@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" <ca****@telkomsa.net> skrev i en meddelelse
news:op**************@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 <ca****@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 <it***@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



Jul 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.