[Tutor] How to take in 2 or more values from user on a single line (like parameters?)

Boykie Mackay boykie.mackay at gmail.com
Wed Sep 19 22:36:07 CEST 2007


Hi again,

I have racked my brains and tried googling but to no avail.

Is there any simple way of getting parameter input from the user?

What I want to do is to type in two (or more) values on the command
prompt and have a function do some work on them and return a result.For
example say I had a multiplication function that I wanted to work as
follows:

me at computer:~/dir/project$python multiply.py
me at computer:~/dir/project$10 12 [enter]
me at computer:~/dir/project$120

Basically I want to start the program 'multiply.py',then be presented
with a blank screen in which I enter the numbers I want multipied
seperated by a space e.g 1 10 11 to give an answer of 110.I have used
the raw_input() and input() functions but it seems they only take on
value at a time!

I suppose what I'm really asking is how to receive muliple values of
input from a user on a single line?
 



More information about the Tutor mailing list