Python: can not import lxml.etree.xmlfile
Trying to use lxml for xml file generation.
in API documentation it is stated that class xmlfile exists: http://lxml.de/api/lxml.etree.xmlfile-class.html
I use import:
from lxml import etree
but when executing getting an error
global name 'xmlfile' is not defined" on line: with xmlfile(os.path.join(self.path, "filename.xml"), encoding='windows-1251') as xf:
Python import semantics are different than you seem to expect.
from <package> import <name>
doesn't make all names in <name> available.
You need to go through <name>, so in your case etree.xmlfile.
You need to change xmlfile to etree.xmlfile.
from lxml import etree ### don't change this with etree.xmlfile(os.path.join(self.path, "filename.xml"), encoding='windows-1251') as xf: