Skip to content

Instantly share code, notes, and snippets.

@2hands10fingers
Created February 20, 2017 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2hands10fingers/f1723da3f00c8983b9d51a490619b9dd to your computer and use it in GitHub Desktop.
Save 2hands10fingers/f1723da3f00c8983b9d51a490619b9dd to your computer and use it in GitHub Desktop.
import math
class MyProcessingClass:
def __init__(self, str_list):
self._str_list = str_list
self._float_list = []
self._strings_to_floats()
# the function to convert the list
# of strings into a list of floats
def _strings_to_floats(self):
for i in self._str_list:
try:
num = int(i)
if not math.isnan(num):
self._float_list.append(num)
except ValueError:
pass
# process the list of floats in some way
def process_input(self):
print(self._float_list)
input_1 = list("123abc")
proc_1 = MyProcessingClass(input_1)
proc_1.process_input()
input_2 = ['1.2', '2', 'NaN', 'foo', '0x8', 'bar']
proc_2 = MyProcessingClass(input_2)
proc_2.process_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment