Contents

  1. command_line_args.py

command_line_args.py

# Demonstrate use of command-line arguments
# by Sara Sprenkle
# Usage: python command_line_args.py filename

import sys

PROG_ARG_LOC=0
FILENAME_ARG_LOC=1

# Make sure there are a sufficient number of arguments
# If not, exit.
if len(sys.argv) < 2:
    print("Error: invalid number of command-line arguments")
    print("Usage: python", sys.argv[PROG_ARG_LOC],"<filename>")
    sys.exit(1)

# Get the 2nd element from the command line and use that as
# the filename    
filename = sys.argv[FILENAME_ARG_LOC]
print("We will process the file named", filename)

# here's where we would process the file ...


Generated by GNU Enscript 1.6.6.