Skip to content

Commit 3d0b7c5

Browse files
committed
Post final QA
1 parent 2e7d0f2 commit 3d0b7c5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

python-double-underscore/cart.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
class 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...

python-double-underscore/mangling.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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=}")

0 commit comments

Comments
 (0)