0
votes

I have this code in python 2.7

from lxml import etree
def file_dialog(self):
    global root1
    fd = QtGui.QFileDialog(self)
    self.f1 = fd.getOpenFileName()
    tree1 = etree.parse(self.f1)

when I execute this I get this error tree1 = etree.parse(self.f1) File "lxml.etree.pyx", line 3310, in lxml.etree.parse (src\lxml\lxml.etree.c:72517) File "parser.pxi", line 1814, in lxml.etree._parseDocument (src\lxml\lxml.etree.c:106226) TypeError: cannot parse from 'QString'

this happens only with python 2.7 the same code works with python 3.4

1

1 Answers

0
votes

I found the solution like this:

from lxml import etree
from StringIO import StringIO

self.f1 = fd.getOpenFileName()
    f=open(self.f1)
    xml=f.read()
    f.close()

    tree1 = etree.parse(StringIO(xml))