Skip to content

Commit 3e5f934

Browse files
committed
🎉 提交在线阅读笔记
1 parent 4b8e28f commit 3e5f934

36 files changed

+5977
-373
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
# 《流畅的Python》阅读笔记
22

3-
原书的项目地址:https://github.com/fluentpython/example-code-2e
3+
原书的项目地址:https://github.com/fluentpython/example-code-2e
4+
5+
## 项目结构
6+
<pre>
7+
assets---------------------------------------------示例代码
8+
docs-----------------------------------------------学习笔记
9+
notes----------------------------------------------学习笔记JupyterNotebook格式
10+
</pre>

assets/16-op-overloading/vector_v6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def frombytes(cls, octets):
351351
def __add__(self, other):
352352
try:
353353
pairs = itertools.zip_longest(self, other, fillvalue=0.0)
354-
return Vector(a + b for a, b in pairs)
354+
return self.__class__(a + b for a, b in pairs)
355355
except TypeError:
356356
return NotImplemented
357357

assets/16-op-overloading/vector_v7.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ def __abs__(self):
337337
return math.hypot(*self)
338338

339339
def __neg__(self):
340-
return Vector(-x for x in self)
340+
return self.__class__(-x for x in self)
341341

342342
def __pos__(self):
343-
return Vector(self)
343+
return self.__class__(self)
344344

345345
def __bool__(self):
346346
return bool(abs(self))
@@ -400,7 +400,7 @@ def frombytes(cls, octets):
400400
def __add__(self, other):
401401
try:
402402
pairs = itertools.zip_longest(self, other, fillvalue=0.0)
403-
return Vector(a + b for a, b in pairs)
403+
return self.__class__(a + b for a, b in pairs)
404404
except TypeError:
405405
return NotImplemented
406406

@@ -412,7 +412,7 @@ def __mul__(self, scalar):
412412
factor = float(scalar)
413413
except TypeError:
414414
return NotImplemented
415-
return Vector(n * factor for n in self)
415+
return self.__class__(n * factor for n in self)
416416

417417
def __rmul__(self, scalar):
418418
return self * scalar

assets/16-op-overloading/vector_v8.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def __bytes__(self):
328328

329329
# tag::VECTOR_V8_EQ[]
330330
def __eq__(self, other):
331-
if isinstance(other, Vector): # <1>
331+
if isinstance(other, self.__class__): # <1>
332332
return (len(self) == len(other) and
333333
all(a == b for a, b in zip(self, other)))
334334
else:
@@ -343,10 +343,10 @@ def __abs__(self):
343343
return math.hypot(*self)
344344

345345
def __neg__(self):
346-
return Vector(-x for x in self)
346+
return self.__class__(-x for x in self)
347347

348348
def __pos__(self):
349-
return Vector(self)
349+
return self.__class__(self)
350350

351351
def __bool__(self):
352352
return bool(abs(self))
@@ -406,7 +406,7 @@ def frombytes(cls, octets):
406406
def __add__(self, other):
407407
try:
408408
pairs = itertools.zip_longest(self, other, fillvalue=0.0)
409-
return Vector(a + b for a, b in pairs)
409+
return self.__class__(a + b for a, b in pairs)
410410
except TypeError:
411411
return NotImplemented
412412

@@ -415,7 +415,7 @@ def __radd__(self, other):
415415

416416
def __mul__(self, scalar):
417417
if isinstance(scalar, numbers.Real):
418-
return Vector(n * scalar for n in self)
418+
return self.__class__(n * scalar for n in self)
419419
else:
420420
return NotImplemented
421421

codes/ch01/french_deck.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

codes/ch01/vector2d.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

codes/ch03/creator.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

codes/ch03/index.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

codes/ch03/index0.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

codes/ch03/index_default.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)