第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

python3中在命令行里使用(sys.argv)cat.py后面加參數(shù),提示錯(cuò)誤

python3中在命令行里使用(sys.argv)cat.py后面加參數(shù),提示錯(cuò)誤

拉風(fēng)的咖菲貓 2019-02-17 06:36:36
系統(tǒng):windowsIDLE:spyderpython3 #!/usr/bin/python # Feilname:cat.py import sys def readfile(filename): '''Print a file to the standard output.''' f = open(filename) while True: line = f.readline() if len(line) == 0: break print(line,) # Notice comma f.close # Script starts from here if len(sys.argv) < 2: print('No action specified.') sys.exit() if sys.argv[1].startswith('--'): option = sys.argv[1][2:] # fetch sys.argv[1] but without the first two characters if option == 'version': print('Version1.2') elif option == 'help': print('''\ This is progarm prints files to the standard ouput. Any number of files can be specified. Options inculde: --Version:Prints the version number --help :Dispay this help''') else: print('Unknown option.') sys.exit() else: for filname in sys.argv[1:]: readfile(filename) cmd命令行運(yùn)行結(jié)果: D:\python-spyder>python cat.py No action specified. D:\python-spyder>python cat.py --version Version1.2 D:\python-spyder>python cat.py poem.txt Traceback (most recent call last): File "cat.py", line 38, in <module> readfile(filename) NameError: name 'filename' is not defined 教程對(duì)應(yīng)參數(shù)結(jié)果: $ python cat.py No action specified. $ python cat.py --version Version 1.2 $ python cat.py poem.txt Programming is fun When the work is done if you wanna make your work also fun: use Python! 前兩個(gè)輸出都是沒(méi)有問(wèn)題,但是在第三個(gè)加入cat.py同目錄下的poem.txt參數(shù)的時(shí)候,卻提示了錯(cuò)誤,這個(gè)問(wèn)題是出在哪里呢?
查看完整描述

1 回答

?
四季花海

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊

烏龍了,自己排除法,結(jié)果發(fā)現(xiàn)問(wèn)題是

else:
    for filname in sys.argv[1:]:
        readfile(filename) 

filname打錯(cuò),改為filename.
然后跟入文件名,ok了

查看完整回答
反對(duì) 回復(fù) 2019-03-01
  • 1 回答
  • 0 關(guān)注
  • 749 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)