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:

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:

Need Your Help

Is there a way to set a font to apply to an entire email?

css html-email

I've been trying to apply a font to an entire email (which is composed of a table).

How to add background image for options in a select box?

javascript jquery html css cross-browser

Can anyone give me a cross-browser supported solution for this problem?