Skip to content

Consider parse function for str to bool #4

Description

@jlevy

http://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python

Probably something like this is best, as it's strict but reasonable:

def parse_bool(val):
  if val in [True, 1, "True", "true"]:
    return True
  elif val in [False, 0, "False", "false"]:
    return False
  else:
    raise ValueError("Not parsable as a boolean: %r" % val)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions