Reputation: 289
I came across this "command line arguments" thing while reading a coding book. Can someone please explain what is it, what is it for and when do I need it?
Upvotes: 0
Views: 81
Reputation: 3576
Python supports the creation of programs that can be run on the command line, completely with command-line arguments.
Example:
import sys
for x in sys.argv:
print("Argument: ", x)
Running:
python demo.py Hey Bye
Output:
Argument: demo.py
Argument: Hey
Argument: Bye
Upvotes: 1
Reputation: 1512
you can always start a python code from the console, like so:
python myCode.py
Now sometimes you want to tell you programs some further infos, then you would type something like:
python myCode.py name=George
In your code you can read those data and use them.
It's a very easy way to change a programs behaviour for users, admins and so one without changing the code.
Upvotes: 1