Skip to content

Commit 75d8aae

Browse files
committed
Fixing items for proofed copy
1 parent 178f786 commit 75d8aae

28 files changed

Lines changed: 17 additions & 16 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.pyc

‎example_code/item_07.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343

4444
# Example 5
45-
chile_ranks = {'ghost': 1, 'habañero': 2, 'cayenne': 3}
45+
chile_ranks = {'ghost': 1, 'habanero': 2, 'cayenne': 3}
4646
rank_dict = {rank: name for name, rank in chile_ranks.items()}
4747
chile_len_set = {len(name) for name in rank_dict.values()}
4848
print(rank_dict)

‎example_code/item_13.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
# Example 2
3535
import json
3636

37-
def load_json_key(data, key):
37+
def load_json_key(data, key):
3838
try:
3939
result_dict = json.loads(data) # May raise ValueError
4040
except ValueError as e:
41-
raise KeyError() from e
41+
raise KeyError from e
4242
else:
4343
return result_dict[key] # May raise KeyError
4444

‎example_code/item_22.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def average_grade(self, name):
104104
total_weight += weight
105105
score_sum += subject_avg / total_weight
106106
score_count += 1
107-
return score_sum / float(score_count)
107+
return score_sum / score_count
108108

109109

110110
# Example 8

‎example_code/item_30.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, period):
2929
self.reset_time = datetime.now()
3030
self.quota = 0
3131

32-
def __str__(self):
32+
def __repr__(self):
3333
return 'Bucket(quota=%d)' % self.quota
3434

3535
bucket = Bucket(60)
@@ -86,7 +86,7 @@ def __init__(self, period):
8686
self.max_quota = 0
8787
self.quota_consumed = 0
8888

89-
def __str__(self):
89+
def __repr__(self):
9090
return ('Bucket(max_quota=%d, quota_consumed=%d)' %
9191
(self.max_quota, self.quota_consumed))
9292

‎example_code/item_32.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __getattr__(self, name):
7979
value = 'Value for %s' % name
8080
setattr(self, name, value)
8181
return value
82-
82+
8383
data = MissingPropertyDB()
8484
data.foo # Test this works
8585
data.bad_name
@@ -106,7 +106,7 @@ def __getattr__(self, name):
106106
# Example 8
107107
class SavingDB(object):
108108
def __setattr__(self, name, value):
109-
# Save some data to the DB
109+
# Save some data to the DB log
110110
pass
111111
super().__setattr__(name, value)
112112

‎example_code/item_35.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class Customer(object):
5353
# Example 4
5454
class Meta(type):
5555
def __new__(meta, name, bases, class_dict):
56-
for name, value in class_dict.items():
56+
for key, value in class_dict.items():
5757
if isinstance(value, Field):
58-
value.name = name
59-
value.internal_name = '_' + name
58+
value.name = key
59+
value.internal_name = '_' + key
6060
cls = type.__new__(meta, name, bases, class_dict)
6161
return cls
6262

‎example_code/item_41.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Example 1
2424
def gcd(pair):
2525
a, b = pair
26-
high, low = max(a, b), min(a, b)
26+
low = min(a, b)
2727
for i in range(low, 0, -1):
2828
if a % i == 0 and b % i == 0:
2929
return i

‎example_code/item_45.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@
9191

9292
# Example 9
9393
nepal = pytz.timezone('Asia/Katmandu')
94-
nepa_dt = nepal.normalize(utc_dt.astimezone(nepal))
95-
print(nepa_dt)
94+
nepal_dt = nepal.normalize(utc_dt.astimezone(nepal))
95+
print(nepal_dt)

‎example_code/item_47.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from decimal import ROUND_UP
4848
rate = Decimal('1.45')
4949
seconds = Decimal('222') # 3*60 + 42
50-
cost = rate * seconds / 60
50+
cost = rate * seconds / Decimal('60')
5151
print(cost)
5252

5353

@@ -59,7 +59,7 @@
5959
# Example 7
6060
rate = Decimal('0.05')
6161
seconds = Decimal('5')
62-
cost = rate * seconds / 60
62+
cost = rate * seconds / Decimal('60')
6363
print(cost)
6464

6565

0 commit comments

Comments
 (0)