"AttributeError: 'xml.etree.ElementTree.Element' object has no attribute...
Brought to you by:
dkuhlman
Hi,
I was receiving the error
self.ns_prefix_ = node.prefix
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'prefix'
when parsing an xml string using the generated python code. It was the identical error posted here
https://github.com/andrebrait/1g1r-romset-generator/issues/3
Here is the patch that was posted in response.
https://github.com/andrebrait/1g1r-romset-generator/commit/402ef60534ae4e25bd64eb066caf0f93dde84373
I ended up installing lxml and then the error went away. A possible fix is to make lxml a required package for installation in setup.py?
Mark Lai
Mark,
Making Lxml a requirement sounds like a good idea to me.
In
generateds/setup.py
, I already find the following, but Ican't find any documentation on what it does.
Is that what you were suggesting?
Or is there something more that I should do?
Dave
Actually, I think my suggestion was poor! =)
I think we can just remove the try import statement from the generated code
i.e. changing
try:
from lxml import etree as etree_
except ModulenotfoundExp_ :
from xml.etree import ElementTree as etree_
to just
from lxml import etree as etree_
We won't know what python environment the user is running the generated
python script from so by forcing the lxml import the user will know that
lxml is required. Perhaps this requirement to run generated python scripts
can be added to the documentation somewhere also.
On Fri, Aug 13, 2021 at 12:51 PM Dave Kuhlman dkuhlman@users.sourceforge.net wrote:
Related
Tickets: #17
Mark,
I've removed the
try/except
from around the import oflxml
. I agree with you. That was a trap waiting to bite someone. I apologize that it was you.I worry that there might be someone out there who has distributed a module generated by
gDS
and who does not want to require all their users to installlxml
. But, requiringlxml
makes their code safer and they should do it for their own good and their users good, and tough love, etc.The new version (v. 2.39.4) is at SourceForge and PyPI.
Thanks for the nudge on this.
Dave
Last edit: Dave Kuhlman 2021-08-17
Sounds good!
I'm curious what your thoughts on the patch posted by Andre.
https://github.com/andrebrait/1g1r-romset-generator/commit/402ef60534ae4e25bd64eb066caf0f93dde84373
Could that be a compromise? The next major release could then require lxml?
On Tue, Aug 17, 2021 at 5:19 PM Dave Kuhlman dkuhlman@users.sourceforge.net
wrote:
Related
Tickets: #17
Dear all,
I am using generateDS since 2014 and it is a fantastic tool, thanks Dave!
I have recently switched to 2.43.1 and I have the problem reported above:
I am using Python 3.10.10 packaged by conda-forge and lxml is installed. I attach here the xsd I am using and a file to test the class produced.
Any help will be greatly appreciated.
Many thanks in advance and best regards,
Marco Bomben
Last edit: Marco Bomben 2023-04-20