Why doesn't Python include non-blocking keyboard input function?

BartC bc at freeuk.com
Thu Oct 27 18:02:24 EDT 2016


On 27/10/2016 19:09, BartC wrote:
> On 27/10/2016 17:13, Steve D'Aprano wrote:
>> On Fri, 28 Oct 2016 12:13 am, BartC wrote:

>>>    print "Enter 3 numbers: "
>>>    readln a,b,c
>>
>> How is the interpreter supposed to know that a, b, c are numbers? What
>> sort
>> of numbers? 16-bit integers, 80-bit floats, Bignums, complex,
>> Fractions, or
>> something else?
>
>> But in a dynamically typed language, the compiler has no idea what you
>> expect a, b and c to be. So it returns text, and you can convert it
>> yourself.

I notice that when it comes to reading command-line arguments, then 
Python's sys.argv presents them as a list, not one long string.

And the list is just a series of strings, so needing to know whether any 
parameter was a number or whatever obviously wasn't a problem. It just 
makes each item into a string (actually that might be a better default 
than mine).

This is a very similar issue to reading items from a line of user input.

So why doesn't sys.argv just return a single string if a line is so easy 
to parse?

(That's exactly what Windows' WinMain() function does - optional entry 
point for executables under Windows. But C's main() entry point chops 
the command line up into separate strings like Python.

Also - this might some bearing on why Python does it that way - under 
Linux, a parameter such as *.py is replaced by the names of ALL the 
files that end in .py. (I was rather astonished when I find out. But 
I've recently had to deal with a directory containing 3,400,000 files so 
having a single "*" converted into 3.4 million filenames would be 
unwelcome.))

-- 
Bartc





More information about the Python-list mailing list