jupyter notebook中使用 optparse 库
结论:使用 optparser.parse_args()
时要加入
optparser.add_option(’-f’,’–file’, default=‘hello you need me’, help=“hello you need me”)
源代码:
首先是可以正常使用的代码
···
import optparse
optparser1 = optparse.OptionParser()
optparser1.add_option(’-f’,’–file’, default=‘hello you need me’, help=“hello you need me”)
optparser1.add_option("-w","–write", default=‘1’, type=“int”, help=“write”)
option , args = optparser1.parse_args()
print("option : ",option)
print("args : ",args)
···
output:
option : {‘file’: ‘C:\Users\xx\xxjson’, ‘write’: 1}
args : []
然后是正常传参的代码
import optparse
optparser2 = optparse.OptionParser()
optparser2.add_option("-w","--write", default='1', type="