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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.