You are not using an open file. You are using the file type. The file.write method is then unbound it expected an open file to be bound to:
>>> file <type 'file'> >>> file.write <method 'write' of 'file' objects> >>> file.write(u'Hello') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: descriptor 'write' requires a 'file' object but received a 'unicode'
If you have an already opened file object, then use that; perhaps you have an attribute named file on self:
self.file.write("startElement'" + name + " ' ")
but take into account that because name is a Unicode value you probably want to encode the information to bytes:
self.file.write("startElement'" + name.encode('utf8') + " ' ")
You could also use io.open() function to create a file object that'll accept Unicode values and encode these to a given encoding for you when writing:
file_object = io.open(filename, 'w', encoding='utf8')
but then you need to be explicit about always writing Unicode values and not mix byte strings (type str) and Unicode strings (type unicode).