I have a Python class for a Person
object which inherits xml.etree.ElementTree.Element
.
from xml.etree import ElementTree
class Person(ElementTree.Element):
def __init__(self, name, age):
super().__init__("person", name=name, age=str(age))
person = Person("Paul", 23)
I plan on expanding my Person
class to include additional attributes and subtags. Before doing this, I want to simplify attribute access by converting my class to use lxml.objectify.Element
.
from lxml import objectify
class Person(objectify.Element):
def __init__(self, name, age):
super().__init__("person", name=name, age=str(age))
person = Person("Paul", 23)
Unfortunately, trying to inherit from objectify.Element
raises a TypeError about creating cython_function_or_method
instances.
Traceback (most recent call last):
File "C:/Users/svascellar/.PyCharmCE2017.3/config/scratches/scratch_1.py", line 2, in <module>
class Person(objectify.Element):
TypeError: cannot create 'cython_function_or_method' instances
Why is my class raising a TypeError? How do I inherit frrom lxml.objectify.Element
?