Skip to content

Commit 1f2128f

Browse files
authored
Merge pull request dabeaz#14 from yukinarit/master
Add missing import functools in chapter 7
2 parents 8a71861 + 53a7ff2 commit 1f2128f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example1.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Example of using partial() with sorting a list of (x,y) coordinates
22

3+
import functools
4+
35
points = [ (1, 2), (3, 4), (5, 6), (7, 7) ]
46

57
import math
@@ -9,5 +11,5 @@ def distance(p1, p2):
911
return math.hypot(x2 - x1, y2 - y1)
1012

1113
pt = (4,3)
12-
points.sort(key=partial(distance, pt))
14+
points.sort(key=functools.partial(distance, pt))
1315
print(points)

src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Using partial to supply extra arguments to a callback function
22

3+
import functools
4+
35
def output_result(result, log=None):
46
if log is not None:
57
log.debug('Got: %r', result)
@@ -17,6 +19,6 @@ def add(x, y):
1719
log = logging.getLogger('test')
1820

1921
p = Pool()
20-
p.apply_async(add, (3, 4), callback=partial(output_result, log=log))
22+
p.apply_async(add, (3, 4), callback=functools.partial(output_result, log=log))
2123
p.close()
2224
p.join()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy