py2neo: Why using class attributes?

  1. 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?

  2. 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! 🙂

Add Comment
1 Answer(s)

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.

Answered on July 15, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.