I'm reading an online book on Python.It mentioned command line arguments,but I don't know what they are? Can anybody explain them for me with an example?
-
Your question is too broad, Read from here http://www.tutorialspoint.com/python/python_command_line_arguments.htm – Ahsanul Haque Oct 05 '15 at 19:10
2 Answers
I don't know what your level of programming experience is, but command line arguments are a pretty common thing. In the olden days, every program you created was done in a text editor, and then run on a command line.
The command line is, in simple terms, a program built into the operating system which allows you to run programs by calling them by name. In Windows, this command line is called the Command Prompt. On other operating systems, it is usually called Terminal.
Though you may be familiar with running programs through an IDE, you can also run them from the command line. To run a python program, you could type:
python the_program.py
to run a program, assuming you have python installed and your terminal knows where it is. So command line arguments are a sort of variable/argument you send to a program that is run this way. If you say:
python the_program.py 100 hello 3.35
You can access these values from within your program, by adding
import sys
to the top, and in the body of your code by accessing the array of arguments, named
sys.argv

- 76
- 5
-
I'm just a newbie and English isn't my native language.Thank you! – Mahmood Muhammad Nageeb Oct 05 '15 at 19:32
-
No problem, I'm sorry people are downvoting you! While it's not a difficult question, it can be hard if you are just a beginner. Let me know if I can explain anything else, or make anything from my answer above easier to understand. – forsooth Oct 05 '15 at 19:34
Command line argument are all addition information passed to the script after the name of the script.
Is you run a python script like:
python myscript.py abc 123
Then abc 123
are the command line arguments. They can be accessed in Python as a list as sys.argv
.

- 13,874
- 5
- 41
- 48