#! /usr/bin/python3.2
import sys
if __name__ == '__main__':
if len (sys.argv) < 4:
print ( ['Usage: myscript [Dir] [Old] [New]',
'Please enter Old and New',
'Please enter New'] [len (sys.argv) - 1] )
或者你可以使用 argparse。这不会满足您在问题中的要求,但希望能安抚 JF Sebastian。
#! /usr/bin/python3.2
import argparse
if __name__ == '__main__':
p = argparse.ArgumentParser (description = 'What your program does.')
p.add_argument ('dir', metavar = 'dir', type = str, help = 'The directory')
p.add_argument ('old', metavar = 'old', type = str, help = 'The old value')
p.add_argument ('new', metavar = 'new', type = str, help = 'The new value')
args = p.parse_args ()