Contents

  1. command_line_args.py
  2. python_list.py

command_line_args.py 1/2

[
top][prev][next]
# Demonstrate use of command-line arguments
# by Sara Sprenkle, 11.05.2007
# Usage: python command_line_args.py filename

import sys

# Make sure there are sufficient arguments.
if len(sys.argv) < 2:
    print "Error: invalid number of command-line arguments"
    print "Usage: python", sys.argv[0],"<filename>"
    sys.exit(1)
    
filename = sys.argv[1]
print "We will use file", filename, "as input"


python_list.py 2/2

[
top][prev][next]
# Demonstrate use of getoutput function, printing out which files are
# python scripts.
# by Sara Sprenkle, 11.05.2007

from commands import getoutput

def main():
    output = getoutput("ls *.py")

    python_script_list = output.split()

    for file in python_script_list:
        print file, "is a Python script"

main()

Generated by GNU enscript 1.6.4.