复制
收藏
提问
全网

import sys import getopt def site(): name = None url = None argv = sys.argv[1:] try: opts, args = getopt.getopt(argv, "n:u:") # 短选项模式 except: print("Error") for opt, arg in opts: if opt in ['-n']: name = arg elif opt in ['-u']: url = arg print( name +" " + url) site()

7e69f6118
3个月前
全网
文档
学术
百科
知识库
时间不限
自动

理解问题import sys import getopt def site(): name = None url = None argv = sys.argv[1:] try: opts, args = getopt.getopt(argv, "n:u:") # 短选项模式 except: print("Error") for opt, arg in opts: if opt in ['-n']: name = arg elif opt in ['-u']: url = arg print( name +" " + url) site()

已完成理解import sys import getopt def site(): name = None url = None argv = sys.argv[1:] try: opts, args = getopt.getopt(argv, "n:u:") # 短选项模式 except: print("Error") for opt, arg in opts: if opt in ['-n']: name = arg elif opt in ['-u']: url = arg print( name +" " + url) site()

展开阅读网页

更简洁一些
转笔记
简洁
import sys import getopt def site(): name = None url = None argv = sys.argv[1:] try: opts, args = getopt.getopt(argv, "n:u:") # 短选项模式 except: print("Error") for opt, arg in opts: if opt in ['-n']: name = arg elif opt in ['-u']: url = arg print( name +" " + url) site()
知识树
import sys import getopt def site(): name = None url = None argv = sys.argv[1:] try: opts, args = getopt.getopt(argv, "n:u:") # 短选项模式 except: print("Error") for opt, arg in opts: if opt in ['-n']: name = arg elif opt in ['-u']: url = arg print( name +" " + url) site()
如何使用Python的argparse模块处理命令行参数?
Python中getopt模块与argparse模块有何不同?
在Python脚本中如何实现命令行参数的自动补全功能?

以上内容由AI搜集生成,仅供参考

在线客服