Python実用スクリプト

Pythonで「コマンド」をつくるときの雛形

#!/usr/bin/env python
from optparse import OptionParser
 
cmd = OptionParser(usage = '%prog [-t] [-p X Y Z] input_file output_file')
 
cmd.add_option('-t', '--toggle', action = "store_true", default = False,
               help = 'ON/OFFを与えるだけのオプション')
 
cmd.add_option('-p', '--position', type = 'int', nargs = 3,
               help = 'オプションとして3個の整数X Y Zを与える',
               metavar = 'X Y Z')
 
(opt, argv) = cmd.parse_args()
 
if len(argv) != 2:
    cmd.print_help()
    raise SystemExit
 
input_file = argv[0]
output_file = argv[1]
option_on_off = opt.toggle
option_xyz = opt.position
seminar/python実用スクリプト.txt · 最終更新: 2009/02/03 18:18 by kimi
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0