If you are getting an error while setting the text content of a child element in an XML tree using the ElementTree
library in Python:
child.text = str(double_alphabet[counter])
Then it probably means that either the child
element or double_alphabet[counter]
is not of type str
.
To fix this error, you can try converting both to strings before setting the text
attribute. For example:
main.py43 chars2 lines
If the issue persists, you can add error handling to handle the exceptions thrown in case of invalid type conversions. Here's an example:
main.py135 chars5 lines
This will catch the error and print a custom message that tells you that there was an error when setting the value for the child
element.
Alternatively, you can use the logging
module instead of print
to log errors.
main.py163 chars7 lines
This will log the exception stack trace along with the error message.
gistlibby LogSnag