Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Example of using partial() with sorting a list of (x,y) coordinates

import functools

points = [ (1, 2), (3, 4), (5, 6), (7, 7) ]

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

pt = (4,3)
points.sort(key=partial(distance, pt))
points.sort(key=functools.partial(distance, pt))
print(points)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Using partial to supply extra arguments to a callback function

import functools

def output_result(result, log=None):
if log is not None:
log.debug('Got: %r', result)
Expand All @@ -17,6 +19,6 @@ def add(x, y):
log = logging.getLogger('test')

p = Pool()
p.apply_async(add, (3, 4), callback=partial(output_result, log=log))
p.apply_async(add, (3, 4), callback=functools.partial(output_result, log=log))
p.close()
p.join()