Skip to content

Commit 21cc321

Browse files
author
tuntun
committed
Python3命令行
1 parent e9a1137 commit 21cc321

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

sys_argv.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ def process_command_line(argv):
2222
add_help_option=None)
2323
# define options here:
2424
parser.add_option( # customized description; put --help last
25-
'-h', '--help', action='help',
26-
help='Show this help message and exit.')
25+
'-h', '--help', action='help', help='Show this help message and exit.'
26+
)
2727
parser.add_option(
28-
'-u', '--url', action='store', dest = 'link',
29-
help='Open a link.')
28+
'-u', '--url', action='store', dest = 'link', help='Open a link.'
29+
)
30+
parser.add_option(
31+
'-v', '--version', action='store_true', help='Show version.'
32+
)
33+
parser.add_option(
34+
'-q', '--quit', action='store_false',help='Quit'
35+
)
3036
settings, args = parser.parse_args(argv)
3137
# check number of arguments, verify values, etc.:
3238
if args:
@@ -46,6 +52,10 @@ def run(settings, args):
4652
if settings.link:
4753
webbrowser.open(settings.link, 1)
4854

55+
if settings.version:
56+
print('VERSION 1.0')
57+
58+
4959

5060
if __name__ == '__main__':
5161
status = main()
@@ -57,6 +67,15 @@ def run(settings, args):
5767
python sys_argv.py -h
5868
显示帮助信息
5969
70+
python sys_argv.py -v
71+
显示版本号
72+
6073
python sys_argv.py -u www.163.com
6174
用默认浏览器打开你输入的网址
75+
76+
action四种参数:
77+
help 显示帮助信息
78+
store 需要参数值
79+
store_true 不需要参数值,默认True
80+
store_false 不需要参数值,默认False
6281
"""

0 commit comments

Comments
 (0)