I'm try to write a little module for my project, which will be work with XML, but on imports i'll have a error (on my Debian installed Python 2.7.3):
ImportError: No module named etree.cElementTree
import os
import xml.etree.cElementTree as cET
class XMLArgumentException(ValueError):
def __init__(self, message='Incorrect argument!'):
ValueError.__init__(self)
self.message = message
class XMLFileInfo():
def __init__(self, path):
if (not isinstance(path, str) or not isinstance(path, unicode)) and not path.endswith('.xml'):
raise XMLArgumentException("Incorrect path! Need type path as string and end on '.xml'")
self.__path = path
def createFile(self):
if not os.path.exists(self.__path):
with open(self.__path, 'w+') as xml:
root = cET.Element("FileStorage")
tree = cET.ElementTree(root)
tree.write(xml)
if __name__ == '__main__':
xml_test = XMLFileInfo('test.xml')
xml_test.createFile()
Maybe need update Python to the lastest version, or something else?
No comments:
Post a Comment