Pages

Thursday, May 15, 2014

python: parse boolean from string








def parse_bool(s):
    return s.lower() in ("yes", "true", "T", "1")

NOTE:

bool('foo') # True
bool('') # False
You can not use the above function to parse boolean from string.


No comments:

Post a Comment