Is it possible to run first the program then wait for the input of the user in command line. e.g.
Run...
Process...
Input from the user(in command line form)...
Process...
Is it possible to run first the program then wait for the input of the user in command line. e.g.
|
|||
|
For interactive user input (or piped commands or redirected input)Use For example:
More details can be found here. So, for example, you might have a script that looks like this
If you saved this in For command-line argumentsSuppose you have a script named
Then, you can do that with the following in your script:
Here, |
|||||||||||
|
If you're using Python 3, Python 3 example:
|
|||
|
Just Taking Input
And that's it. Moreover, if you want to make a list of inputs, you can do something like:
In that case, you'll be asked for data 10 times to store 9 items in a list. Output:
You can search that list the fundamental way with something like (after making that list):
else: print "Not found." You can replace '2' with "raw_input()" like this:
Taking Raw Data From Input File via Commandline InterfaceIf you want to take the input from a file you feed through commandline (which is normally what you need when doing code problems for competitions, like Google Code Jam or the ACM/IBM ICPC): example.py
In command line interface:
Hope that helps. |
|||||||||||||||||
|