Emulating Pascal input
Peter Hansen
peter at engcorp.com
Wed May 22 08:27:02 EDT 2002
Michael Williams wrote:
>
> Consider the following Pascal code:
>
> (******** Pascal code **********)
> (* Pascal ascii input of numbers: stdin and file *)
> readln(x, y);
> readln(fin, x, y);
>
> The first line is for stdin, the second for from file. The variables
> x and y will then contain the first two white space separated numbers
> the program encounters when that function is called.
Does that mean if I were to type "i have 3 out of 6 on the test"
that x would equal 3 and y would equal 6? Or what would I get
if I typed "3 6 blah blah"?
It looks like readln() is a convenience function without directly
compatible equivalents in many other languages. Maybe you could
spend a brief time having the students work with the raw data
as you have in your examples, then present them with a nice
utility method that works in a non-readln manner (more Pythonic
would be good, with exceptions) and let them use that the rest
of the time. You could even stick it in _builtins_ via site.py
or something, so they never know it isn't standard (until they
try to use it elsewhere).
I remember writing such little programs in school at various
times, but in reality I don't think real programs ever do such
things. They parse command line arguments (maybe you could
teach them about Optik) or they handle input from a GUI,
but reading non-trivial data directly from stdin seems uncommon
outside of contrived assignments in school.
-Peter
More information about the Python-list
mailing list