473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

sys.stdin.read question

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
9 13002
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
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
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

"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stelios G. Sfakianakis | last post by:
Hello, I am using php 4.2.2 in Red Hat 9.0 with apache 2.0.40 I try to build a php script that accepts POST requests that contain multimedia data and shoves them in a MySQL database. My problem is...
7
by: Yandos | last post by:
Hello all, I have maybe a trivial question, but I cannot think out what is wrong :( How do i detect EOF correctly when i read from stdin? Am I doing it wrong? <pipetest.c> #include <stdio.h>...
3
by: Harayasu | last post by:
Hi, Using fgets() I can read from stdin and with fputs() I can write to stdout. Now I have two programs, one writing to stdin and the other one reading from stdin. And I would like the second...
23
by: herrcho | last post by:
What's the difference between STDIN and Keyboard buffer ? when i get char through scanf, i type in some characters and press enter, then, where do the characters go ? to STDIN or Keyboard...
6
by: chad kline | last post by:
FBSD 4.8/GCC //////// C-CODE: //////// char c; while ( 1 ) {
11
by: David Warner | last post by:
Greetings! I need to write some C code that will decide between either reading from stdin or take a file name from argv and process it. The program needs to work like all of the typical unix...
1
by: asdsd sir | last post by:
Hi!I'm new in Python and i'd like to ask some general questions about stdin,stdout... Firstly... if we type like something like : cat "file.txt"|python somefile.py #somefile.py import sys
6
by: Kevin Simmons | last post by:
I have seen this question asked a few times but have not seen a clear answer... I have a python script that prompts the user for input from stdin via a menu. I want to process that input when...
31
by: Nikos Chantziaras | last post by:
Hello. Is there a way to check if the current process has an stdin handle? In the win32 API, one can do: _eof(_fileno(stdin)) Crucial here is that the above doesn't block. Is there a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.