File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 11class ShoppingCart :
2- def __init__ (self , customer_id ):
3- self .customer_id = customer_id
2+ def __init__ (self ):
43 self .products = []
54
65 def add_product (self , product ):
@@ -11,5 +10,3 @@ def get_products(self):
1110
1211 def __len__ (self ):
1312 return len (self .products )
14-
15- # Implementation...
Original file line number Diff line number Diff line change @@ -13,3 +13,20 @@ def __init__(self):
1313
1414 def __method (self ): # Doesn't override A.__method()
1515 print ("B.__attr = " , self .__attr )
16+
17+
18+ if __name__ == "__main__" :
19+ a = A ()
20+ b = B ()
21+
22+ # Call the mangled methods
23+ print (f"{ a ._A__method ()= } " )
24+ print (f"{ b ._B__method ()= } " )
25+
26+ # Check attributes
27+ print (f"{ a .__dict__ = } " )
28+ print (f"{ b .__dict__ = } " )
29+
30+ # Access the attributes on b
31+ print (f"{ b ._A__attr = } " )
32+ print (f"{ b ._B__attr = } " )
You can’t perform that action at this time.
0 commit comments