File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 66
77import optparse
88import sys
9+ import webbrowser
910
1011
1112def process_command_line (argv ):
@@ -23,6 +24,9 @@ def process_command_line(argv):
2324 parser .add_option ( # customized description; put --help last
2425 '-h' , '--help' , action = 'help' ,
2526 help = 'Show this help message and exit.' )
27+ parser .add_option (
28+ '-u' , '--url' , action = 'store' ,
29+ help = 'Open a link.' )
2630 settings , args = parser .parse_args (argv )
2731 # check number of arguments, verify values, etc.:
2832 if args :
@@ -34,9 +38,24 @@ def process_command_line(argv):
3438def main (argv = None ):
3539 settings , args = process_command_line (argv )
3640 # application code here, like:
37- # run(settings, args)
41+ run (settings , args )
3842 return 0 # success
3943
44+ def run (settings , args ):
45+ if settings .url :
46+ webbrowser .open (settings .url , 1 )
47+
48+
4049if __name__ == '__main__' :
4150 status = main ()
42- sys .exit (status )
51+ sys .exit (status )
52+
53+ """
54+ 命令行功能:
55+
56+ python sys_argv.py -h
57+ 显示帮助信息
58+
59+ python sys_argv.py -u www.163.com
60+ 用默认浏览器打开你输入的网址
61+ """
You can’t perform that action at this time.
0 commit comments