我正在使用DyMat Python软件包将变量从.mat文件导出到.csv。 但是,导出的.csv文件都是只读的吗?为什么会这样,有解决方案吗?
我尝试正确关闭()文件或在Python中删除文件,但这没有用。还有其他建议吗?
import csv, numpy, os
import DyMat
os.chdir("C:/Users/myvhove/Documents/ResultsPyDymInt/Dymola/CoupledClutches")
print(os.getcwd())
dm = DyMat.DyMatFile("dymatresfile")
print(dm.fileName)
print(dm.names())
varList = ('J1.w', 'J2.w', 'J3.w', 'J4.w')
fileName = dm.fileName + '.csv'
oFile = open(fileName, 'w', newline='')
csvWriter = csv.writer(oFile)
vDict = dm.sortByBlocks(varList)
for vList in vDict.values():
vData = dm.getVarArray(vList)
vList.insert(0, dm._absc[0])
csvWriter.writerow(vList)
csvWriter.writerows(numpy.transpose(vData))
oFile.close()