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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python中的文件名處理錯誤

python中的文件名處理錯誤

慕森王 2021-03-25 06:11:08
顯示此錯誤的最小工作示例:from os import listdir, getcwdfrom os.path import isfile, join, realpath, dirnameimport csvdef gd(mypath, myfile):    # Obtain the number of columns in the data file    with open(myfile) as f:        reader = csv.reader(f, delimiter=' ', skipinitialspace=True)        for i in range(20):            row_20 = next(reader)        # Save number of clumns in 'num_cols'.        num_cols = len(row_20)        return num_colsmypath = realpath(join(getcwd(), dirname(__file__)))# Iterate through all files. Stores name of file in 'myfile'.for myfile in listdir(mypath):    if isfile(join(mypath,myfile)) and (myfile.endswith('.dat')):        num_cols = gd(mypath, myfile)print(num_cols)我在該文件夾中只有一個名為“ data.dat”的文件,并python返回錯誤:----> 9     with open(myfile) as f:....IOError: [Errno 2] No existe el archivo o el directorio: u'data.dat'轉(zhuǎn)換為無文件或目錄:u'data.dat'。為什么在文件名的開頭添加u,如何獲取正確解析文件名的代碼?
查看完整描述

2 回答

?
守著星空守著你

TA貢獻1799條經(jīng)驗 獲得超8個贊

您的問題在于,這myfile只是文件名,而不是的結(jié)果join(mypath,myfile)。


查看完整回答
反對 回復(fù) 2021-03-30
  • 2 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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