Skip to content

Commit 18d8327

Browse files
committed
-
1 parent 5b3ce03 commit 18d8327

File tree

51 files changed

+61
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+61
-50
lines changed

source_py2/python_toolbox/context_management/base_classes/decorating_context_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
See its documentation for more information.
88
'''
99

10-
from __future__ import with_statement
1110

1211
from python_toolbox import decorator_tools
1312

source_py2/python_toolbox/context_management/context_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
See its documentation for more information.
88
'''
99

10-
from __future__ import with_statement
1110

1211
import sys
1312
import types

source_py2/python_toolbox/cute_iter_tools.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# exception
77

88
from __future__ import division
9-
from __future__ import with_statement
109

1110
import collections
1211
import itertools
@@ -259,5 +258,18 @@ def make_false_iterator():
259258
return (make_true_iterator(), make_false_iterator())
260259

261260

262-
263261

262+
def get_ratio(filter_function, iterable):
263+
if isinstance(filter_function, str):
264+
attribute_name = filter_function
265+
filter_function = lambda item: getattr(item, attribute_name, None)
266+
n_total_items = 0
267+
n_passed_items = 0
268+
for item in iterable:
269+
n_total_items += 1
270+
if filter_function(item):
271+
n_passed_items += 1
272+
return n_passed_items / n_total_items
273+
274+
275+

source_py2/python_toolbox/emitting/emitter_system/emitter_system.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
See documentation of EmitterSystem for more info.
88
'''
99

10-
from __future__ import with_statement
1110

1211
import itertools
1312

source_py2/python_toolbox/math_tools.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import numbers
99

1010

11+
infinity = float('inf')
12+
13+
1114
def get_sign(x):
1215
'''Get the sign of a number.'''
1316
if x > 0:
@@ -85,4 +88,20 @@ def get_mean(iterable):
8588
for i, value in enumerate(iterable):
8689
sum_ += value
8790
return sum_ / (i + 1)
88-
91+
92+
93+
94+
def restrict_number_to_range(number, low_cutoff=-infinity,
95+
high_cutoff=infinity):
96+
'''
97+
If `number` is not in the range between cutoffs, return closest cutoff.
98+
99+
If the number is in range, simply return it.
100+
'''
101+
if number < low_cutoff:
102+
return low_cutoff
103+
elif number > high_cutoff:
104+
return high_cutoff
105+
else:
106+
return number
107+

source_py2/python_toolbox/nifty_collections/lazy_tuple.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
See its documentation for more information.
88
'''
99

10-
from __future__ import with_statement
1110

1211
import threading
1312
import collections

source_py2/python_toolbox/queue_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
'''Defines various functions for working with queues.'''
55

6-
from __future__ import with_statement
76

87
import Queue as queue_module
98
import sys

source_py2/python_toolbox/sys_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'''Defines various `sys`-related tools.'''
55

66

7-
from __future__ import with_statement
87

98
import sys
109
import cStringIO

source_py2/python_toolbox/temp_file_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
'''Defines various tools related to temporary files.'''
55

6-
from __future__ import with_statement
76

87
import tempfile
98
import shutil

source_py2/python_toolbox/wx_tools/widgets/cute_dialog_type.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
See its documentation for more information.
88
'''
99

10-
from __future__ import with_statement
1110

1211
import wx
1312

0 commit comments

Comments
 (0)