Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python etree xml写入问题_Python_Xml_Elementtree - Fatal编程技术网

Python etree xml写入问题

Python etree xml写入问题,python,xml,elementtree,Python,Xml,Elementtree,我尝试将多个文件写入一个目录,每个文件之间的更改很少(例如,增量id号)。当我尝试运行我的程序时,在写入大约5个文件后失败。但是,当我再次尝试并重新选择源文件时,它可以工作。这是我的密码: if not os.path.isdir(self.fDirectory + "/AutoGen" + strftime("%Y-%m-%d %H:%M:%S", gmtime())): os.mkdir(self.fDirectory + "/AutoGen" + str

我尝试将多个文件写入一个目录,每个文件之间的更改很少(例如,增量id号)。当我尝试运行我的程序时,在写入大约5个文件后失败。但是,当我再次尝试并重新选择源文件时,它可以工作。这是我的密码:

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'
任何想法都非常感谢

首先,使用它会让你的生活更轻松

在我看来,
strftime
的第一个和最后一个调用发生在不同的时间(并且您在第一个调用中省略了下划线)。脚本找不到目录,因为它不存在。我敢打赌,一个在几秒钟前就有时间的名字,甚至可能是可疑的

尝试将第一个
if
-语句替换为

dirname = os.path.join(self.fDirectory,strftime("AutoGen%Y-%m-%d_%H.%M.%S",gmtime()))

if not os.path.isdir(dirname):
    os.mkdir(dirname)
最后一行是:

myTree.write(os.path.join(dirname, self.filename + "_" + str(anum) + ".xml"))
首先,使用它,它会让你的生活更轻松

在我看来,
strftime
的第一个和最后一个调用发生在不同的时间(并且您在第一个调用中省略了下划线)。脚本找不到目录,因为它不存在。我敢打赌,一个在几秒钟前就有时间的名字,甚至可能是可疑的

尝试将第一个
if
-语句替换为

dirname = os.path.join(self.fDirectory,strftime("AutoGen%Y-%m-%d_%H.%M.%S",gmtime()))

if not os.path.isdir(dirname):
    os.mkdir(dirname)
最后一行是:

myTree.write(os.path.join(dirname, self.filename + "_" + str(anum) + ".xml"))

很抱歉,这与etree或xml无关。您似乎没有提供python编写toI的正确路径。很抱歉,这与etree或xml无关。您似乎没有为python提供正确的路径来编写ToTanks。这是完全有道理的,我认为这可能与此有关,但我知道的还不够清楚。在代码和strftime末尾添加“)”所需的句点,而不是分号以匹配windows路径约定。现在它似乎工作得很好!谢谢这是完全有道理的,我认为这可能与此有关,但我知道的还不够清楚。在代码和strftime末尾添加“)”所需的句点,而不是分号以匹配windows路径约定。现在它似乎工作得很好!