How to pass command line arguments to your Python program
Here is an example for quick reference. argv
holds the program name at index 0. That's why we start at 1.
#!/usr/bin/python
import sys
def main():
# print command line arguments
for arg in sys.argv[1:]:
print arg
if __name__ == "__main__":
main()
Try it out:
$ python cmdline_args.py arg1 arg2 arg3 arg1 arg2 arg3
See also:
sys
module documentationgetopt
module documentationGuido van Rossum's post