May-24-2023, 07:18 PM
(May-24-2023, 05:37 PM)Gribouillis Wrote: Perhaps you mean this
class A: pass class B: def __init__(self, spam): self.spam = spam class C: def __init__(self, eggs): self.eggs = eggs a = A() # instantiate A b = B(a) bb = B(a) c = C(a) # objects b, bb and c all share the same A instance assert b.spam is bb.spam and b.spam is c.eggs
No, but that gave me an idea.
Is the below legal and will it expose the object created in A outside of A. Example below:
In the main program:
a = A(self) print(b) Class A: def __init__(self, parentobject): parentobject.b = b()I appreciate your time answering this.