Skip to content

Commit

Permalink
Avoid possible issue in bool comparison
Browse files Browse the repository at this point in the history
Looks like Excel converts True/False to uppercase.
Thanks @defiancecp #56 (comment)
  • Loading branch information
oldnapalm authored Aug 24, 2020
1 parent 75eb1e8 commit f3c1ba4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def isForward(state):
def course(state):
return (state.f19 & 0xff0000) >> 16

def boolean(s):
if s.lower() in ['true', 'yes', '1']: return True
if s.lower() in ['false', 'no', '0']: return False
return None

def saveGhost(player_id, name):
if not player_id: return
folder = '%s/%s/ghosts' % (STORAGE_DIR, player_id)
Expand Down Expand Up @@ -97,7 +102,7 @@ def loadGhosts(player_id, state):
if os.path.isfile(sl_file):
with open(sl_file, 'r') as fd:
sl = [tuple(line) for line in csv.reader(fd)]
rt = [t for t in sl if t[0] == str(course(state)) and t[1] == str(roadID(state)) and (t[2] == str(isForward(state)) or not t[2])]
rt = [t for t in sl if t[0] == str(course(state)) and t[1] == str(roadID(state)) and (boolean(t[2]) == isForward(state) or not t[2])]
if rt:
start_road = int(rt[0][3])
start_rt = int(rt[0][4])
Expand Down

0 comments on commit f3c1ba4

Please sign in to comment.