Skip to content

Commit 70c3858

Browse files
committed
Add output, colons, and remove obsolete line
1 parent 8935e90 commit 70c3858

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

python-dict-attribute/config_v3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ def clear(self):
1919
for key in list(self.__dict__.keys()):
2020
delattr(self, key)
2121
print("All options removed!")
22+
23+
24+
conf = Config("GUI App")
25+
conf.set_option("theme", "dark")
26+
conf.set_option("size", "200x400")
27+
print(conf.__dict__)
28+
conf.remove_option("size")
29+
print(conf.__dict__)
30+
conf.remove_option("autosave") # Raises KeyError
31+
print(conf.__dict__)
32+
conf.clear()
33+
print(conf.__dict__)

python-dict-attribute/person.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def as_tuple(self):
2424

2525
john = Person("John", "Doe", 30)
2626
print(repr(john))
27-
Person("John", "Doe", 30)
2827
print(john)
2928
print(john.as_dict())
3029
print(john.as_tuple())

python-dict-attribute/record.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ def __delattr__(self, key):
3030
logging.warning(
3131
f"[DEL] Attempted to delete non-existent field '{key}'"
3232
)
33+
34+
35+
jane = Record(first_name="Jane", last_name="Doe", age=25)
36+
37+
# Access
38+
print(jane.first_name)
39+
print(jane.age)
40+
41+
# Mutations
42+
jane.age = 26
43+
jane.job = "Software Engineer"
44+
print(jane.__dict__)
45+
46+
# Deletion
47+
del jane.age
48+
print(jane.__dict__)

python-dict-attribute/track_calls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def track_calls():
22
track_calls.__dict__["calls"] = track_calls.__dict__.get("calls", 0) + 1
3-
print(f"Calls {track_calls.calls}")
3+
print(f"Calls: {track_calls.calls}")
44

55

66
track_calls()

0 commit comments

Comments
 (0)