I am kinda lost, can't figure out why it is giving me this Attribute error. I am running python 2.7.8 I am trying to test my Classes write to file and calling the ElementTree's write. However it says the write function isn't defined.
>>> import BMECATpreprocess as Bpp
>>>
>>> fibo = Bpp.BMECATpreprocess()
>>> fibo.filename()
Bitte geben Sie den Dateiname inklusive Phad ein: Zoro_CatMap.xml
'Zoro_CatMap.xml'
>>> fibo.writefile()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "BMECATpreprocess.py", line 140, in writefile
AttributeError: 'str' object has no attribute 'write'
my BMECATpreprocess class looks like this:
import xml.etree.ElementTree as ET
tree = ''
root = ''
class BMECATpreprocess():
#init
def __init__(self, keytag='', childkeytag='', tree='', write=''):
self.keytag = keytag
self.childkeytag = childkeytag
self.tree = tree
self.write = write
#ask for filename/location
def filename(self):
data = raw_input("Bitte geben sie den Datei Name inklusive Phad ein: ")
return data
def opentree(self): #open files and initialize the xml file for use
global tree
tree = ET.parse(self.filename())
def getroot(self):
global root
root = tree.getroot()
return root
def writefile(self):
tree.write(self.filename(), encoding="UTF-8", xml_declaration=True)
No comments:
Post a Comment