File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 1- # csv_data.py
2-
31import csv
42
53
Original file line number Diff line number Diff line change 1+ class A :
2+ def __init__ (self ):
3+ self .__attr = 0
4+
5+ def __method (self ):
6+ print ("A.__attr = " , self .__attr )
7+
8+
9+ class B (A ):
10+ def __init__ (self ):
11+ super ().__init__ ()
12+ self .__attr = 1 # Doesn't override A.__attr
13+
14+ def __method (self ): # Doesn't override A.__method()
15+ 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