#!/usr/bin/python
#
# Command-line arguments.
# Unix programs should rarely ask the user for input.
# Instead specify such information on the command line.
# The sys module provides the argv array.
#
# How to use this example program:
# $ ./commandline1.py football 'your arguments here' 789
print """Here are the command-line arguments, one per line
========================================"""
import sys
for arg in sys.argv:
print arg
print """========================================
Notice that sys.argv[0] is the name of the program,
so sys.argv[1] is the first argument.
"""
print "The number of arguments is len(sys.argv)",
print "= %d " % (len(sys.argv))
print """
NOTE: all the arguments are strings. If you want to
treat some of them as numbers, you will need to convert
them -- see commandline2.py.
"""
Credit = """
Sanjoy Mahajan and David MacKay
"""
|