py2neo: Why using class attributes?
-
py2neo uses class attributes to model the attributes of nodes in neo4j. What is the reason (or underlying architecture/philosophy) for not using instance attributes?
-
Would there be an easy (generic) way to convert/map py2neo results (of type GraphObject) into objects with instance attributes?
Thank you for any hints or insights! 🙂
Attributes defined on the class can be overridden by attributes on sub-classes:
class A(object): x = 1 def __init__(self): self.y = 2 class B(A): x = 11 y = 22 b = B() print(b.x, b.y)
will print
11 2
since the x
is overridden when the class B
is created, but then the A.__init__()
method is ran which overwrites self.y
with 2.