想對/A/B/C/D/E/目錄下所有檔案夾及其子檔案夾內的固定2個txt檔案進行某些替換操作,而后生成新檔案。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import glob
import re
with open(glob.glob(os.path.join('/A/B/C/D/E/*/*/*/,X.txt')),'r') as filereader1:
with open(glob.glob(os.path.join('/A/B/C/D/E/*/*/*/,X_new.txt')),'w') as filewriter1:
for row in filereader1:
if "256QAM" in row:
row = row.replace('256QAM', '8')
elif "64QAM" in row:
row = row.replace('64QAM', '6')
elif "16QAM" in row:
row = row.replace('16QAM', '4')
elif "QPSK" in row:
row = row.replace('QPSK', '2')
elif ",31," in row:
row = row.replace(',31,', ',,')
elif ",30," in row:
row = row.replace(',30,', ',,')
elif ",29," in row:
row = row.replace(',29,', ',,')
elif ",28," in row:
row = row.replace(',28,', ',,')
filewriter1.write(row)
with open(glob.glob(os.path.join('/A/B/C/D/E/*/*/*/,Y.txt')),'r') as filereader2:
with open(glob.glob(os.path.join('/A/B/C/D/E/*/*/*/,Y.txt')),'w') as filewriter2:
for row in filereader2:
if "Rank " in row:
row = row.replace('Rank ', '')
filewriter2.write(row)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
報這樣的錯:
TypeError: expected str, bytes or os.PathLike object, not list
uj5u.com熱心網友回復:
glob.glob(os.path.join('/A/B/C/D/E/*/*/*/,X.txt')這個得到的是檔案串列,不是單個的檔案
uj5u.com熱心網友回復:
好的謝謝大神轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/63774.html
上一篇:Kaldi安裝
