Skip to content

Commit

Permalink
Forget getSystem(), the all new "normalized_str" will truly amaze you!
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Aug 15, 2014
1 parent 819d1e2 commit 1c9a6ad
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,17 @@ def fetch_all(self, sql):

def list_search(self, listType, lookup, values):
match = None
needle = lookup.casefold().replace(" ", "").casefold()
needle = self.normalized_str(lookup)
for val in values:
if val.casefold().replace(" ", "").find(needle) > -1:
if self.normalized_str(val).find(needle) > -1:
if match:
raise ValueError("Ambiguity: %s '%s' could match %s or %s" % (
listType, lookup, match, val))
match = val
if not match:
raise LookupError("Error: '%s' doesn't match any %s" % (lookup, listType))
return match


def normalized_str(self, str):
return str.replace(" ", "").casefold()

0 comments on commit 1c9a6ad

Please sign in to comment.