linux – Does Python have an argc argument?
linux – Does Python have an argc argument?
In python a list knows its length, so you can just do len(sys.argv)
to get the number of elements in argv
.
I often use a quick-n-dirty trick to read a fixed number of arguments from the command-line:
[filename] = sys.argv[1:]
in_file = open(filename) # Dont need the r
This will assign the one argument to filename
and raise an exception if there isnt exactly one argument.
linux – Does Python have an argc argument?
Youre better off looking at argparse for argument parsing.
http://docs.python.org/dev/library/argparse.html
Just makes it easy, no need to do the heavy lifting yourself.
Related posts:
- How do you pass command line arguments in shell script?
- c++ – How to work with the 4th argument of the sqlite3_exec function?
- c – Length of array in function argument
- c – Calling yyrestart function in bison with no arguments causing sigsev on El Capitan
- arguments – How do I set default values for functions parameters in MATLAB?
- c – Checking command line argument for valid digit
- Which way is better to pass arrays as function arguments in C?
- Calling a CMake function: number of arguments
- Python CLI Framework and Argument Parsing with Tab Completion
- printf – How to print argv arguments from main function in C?