Re: How do read a single character from stdin?

Mike Tibbs (tibbs@dopey.si.com)
Thu, 10 Mar 94 09:21 EST

> > I am embarrased asking a question like this amongst all this
> > discussion of lambda bindings, but how do you read a single character
> > from stdin?
>
> Don't be embarrassed -- at least this one is easy to answer :-)
>
> You can read n characters from any open file using fp.read(n). You
> can read until EOF using fp.read(). (Here fp is the file pointer --
> read is a method. Check the library manual for more file methods.)
>
> Standard input is sys.stdin. Check the library manual for module sys.
>
> --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
> URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>
>

Guido,

The fp.read method takes a variable number of args, like the C printf.
That's ok, but I would think in an OO language, there would be seperate
methods for reading a set number of chars and for reading until EOF.

fp.readBytes(unsigned int:nbytes)
fp.readEOF()

Maybe readEOF may call readBytes in it's implementation, but that is hidden.

(I've been influenced by Smalltalk, as you may have guessed.)

== Mike Tibbs
== tibbs_michael@si.com