seminar:プログラミング実習
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン次のリビジョン両方とも次のリビジョン | ||
seminar:プログラミング実習 [2020/08/20 17:30] – [Pythonガイド] kimi | seminar:プログラミング実習 [2020/08/20 17:31] – [Pythonガイド] kimi | ||
---|---|---|---|
行 93: | 行 93: | ||
* [[python実用スクリプト]] | * [[python実用スクリプト]] | ||
- | ====== Python実用スクリプト ====== | ||
* [[: | * [[: | ||
行 105: | 行 104: | ||
$ python -i ○○○○.py | $ python -i ○○○○.py | ||
</ | </ | ||
+ | |||
+ | |||
+ | ===== Pythonで「コマンド」をつくるときの雛形 ===== | ||
+ | <code python> | ||
+ | # | ||
+ | from optparse import OptionParser | ||
+ | |||
+ | cmd = OptionParser(usage = '%prog [-t] [-p X Y Z] input_file output_file' | ||
+ | |||
+ | cmd.add_option(' | ||
+ | help = ' | ||
+ | |||
+ | cmd.add_option(' | ||
+ | help = ' | ||
+ | | ||
+ | |||
+ | (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/プログラミング実習.txt · 最終更新: 2023/03/01 15:09 by kimi