diff --git a/src/4/creating_data_processing_pipelines/example.py b/src/4/creating_data_processing_pipelines/example.py index a7ff39a..9a2de51 100644 --- a/src/4/creating_data_processing_pipelines/example.py +++ b/src/4/creating_data_processing_pipelines/example.py @@ -10,7 +10,7 @@ def gen_find(filepat, top): ''' for path, dirlist, filelist in os.walk(top): for name in fnmatch.filter(filelist, filepat): - yield os.path.join(path,name) + yield os.path.join(path, name) def gen_opener(filenames): ''' diff --git a/src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example1.py b/src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example1.py index 85f6517..85e1ae6 100644 --- a/src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example1.py +++ b/src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example1.py @@ -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 @@ -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) diff --git a/src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example2.py b/src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example2.py index bfe4f0e..4071f2e 100644 --- a/src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example2.py +++ b/src/7/making_an_n-argument_callable_work_as_a_callable_with_fewer_arguments/example2.py @@ -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) @@ -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() diff --git a/src/8/implementing_custom_containers/example1.py b/src/8/implementing_custom_containers/example1.py index f8ab10f..a5d6112 100644 --- a/src/8/implementing_custom_containers/example1.py +++ b/src/8/implementing_custom_containers/example1.py @@ -5,7 +5,7 @@ class SortedItems(collections.Sequence): def __init__(self, initial=None): - self._items = sorted(initial) if initial is None else [] + self._items = sorted(initial) if initial is not None else [] # Required sequence methods def __getitem__(self, index): diff --git a/src/8/implementing_custom_containers/example2.py b/src/8/implementing_custom_containers/example2.py index f9cc6a5..cf2fd29 100644 --- a/src/8/implementing_custom_containers/example2.py +++ b/src/8/implementing_custom_containers/example2.py @@ -2,7 +2,7 @@ class Items(collections.MutableSequence): def __init__(self, initial=None): - self._items = list(initial) if initial is None else [] + self._items = list(initial) if initial is not None else [] # Required sequence methods def __getitem__(self, index):
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: