我試圖寫入多個文件到每個文件之間變化很小的目錄(例如增量id號碼)當我嘗試運行我的程序時,寫入大約5個文件後失敗。但是,當我再次嘗試並重新選擇源文件時,它可以正常工作。這裏是我的代碼:Python etree xml寫入問題
if not os.path.isdir(self.fDirectory + "/AutoGen" + strftime("%Y-%m-%d %H:%M:%S", gmtime())):
os.mkdir(self.fDirectory + "/AutoGen" + strftime("%Y-%m-%d_%H.%M.%S", gmtime()))
anum = 0
for x in range(len(self.csvdata)-1):
for y in range(len(self.csvdata[x+1])):
self.myRoot.find(self.csvdata[0][y]).text = self.csvdata[x][y]
anum+=1
myTree.write(self.fDirectory + "/AutoGen" + strftime("%Y-%m-%d_%H.%M.%S", gmtime()) + "/" + self.filename + "_" + str(anum) + ".xml")
這裏就是我得到的錯誤:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "C:\Users\CNash\Documents\XML Generator\XMLGen.py", line 148, in doIt
myTree.write(self.fDirectory + "/AutoGen" + strftime("%Y-%m-%d_%H.%M.%S", gmtime()) + "/" + self.filename + "_" + str(anum) + ".xml")
File "C:\Python32\lib\xml\etree\ElementTree.py", line 836, in write
file = open(file_or_filename, "wb")
IOError: [Errno 2] No such file or directory: 'C:/Users/CNash/Documents/XML Generator/AutoGen2012-07-31_20.23.52/EXuTest_DOCD00140_6.xml'
任何想法非常感謝!
我很抱歉,但這個有沒有關係etree或XML。你似乎沒有提供Python的正確路徑寫入 – 2012-07-31 20:50:02