Is there a possible access to the basic methods / properties in the inside class?
class A: 'a' class classb (): def method (self): return self.a instance = ClassA () instance2 = instance.ClassB () instance2.method () < / Code>
No, relations between nesting instances in a class do not automatically generate All of the attributes you made were created on a class A
, which was a class object, for example, calling that attribute gives class attributes and Classb
one Or example Class A
any instance is created without the knowledge or context.
By passing in the context, you will need to clarify such relationships:
class ClassB (): def __init __ (self, A): self. A = A def method (self): Return Self.a class ClassA: a = 'a' def class_b_factory (self): Return ClassB (self) Example = ClassA () instance2 = instance.class_b_factory () instance2.method () < / Code>
Comments
Post a Comment