Why doesn't Python include non-blocking keyboard input function?
Christian Gollwitzer
auriocus at gmx.de
Sat Oct 29 11:26:55 EDT 2016
Am 29.10.16 um 16:32 schrieb BartC:
> I still think a beginner would much prefer something along the lines of
> 'readln a,b,c' (and I still think that's more intuitive).
>
> (The first programming exercises I ever did involved typing in integers
> from the user, and sorting them or working out if they made a triangle
> or whatever.
Yes, and that's exactly why they learn to produce such horrible
interfaces which do not work for a serious program. Instead, teach them
how to use the *environment* for I/O. That is, as a beginner put your
function into a file, e.g.
def is_triangle(a, b, c):
if abs(a)+abs(b) > abs(c):
print "Triangle!"
else:
print "Not a triangle"
..and then use IPython:
%run triangle.py
>>> is_triangle(1,1.7, 2)
Triangle!
>>> is_triangle(1,1.7, 8)
Not a triangle
>>>
(I know the prog is incomplete, but that's not the point)
This way you can concentrate on the algorithm and leave the I/O thing to
python. Due to the built-in readline, you can recall previous arguments,
edit them when you make mistakes, save the result (if there were any),
.... much more than your readln function can accomplish.
Christian
More information about the Python-list
mailing list