def bool_from_string(subject):
 if isinstance(subject, bool):
  return subject
 elif isinstance(subject, int):
  return (subject == 1)
 if hasattr(subject, 'startswith'):
  if (subject.strip().lower() in ('true', 'on', '1', 'yes', 'y')):
   return True
 return False

def bool_from_string ( subject ) : if isinstance ( subject , bool ) : return subject elif isinstance ( subject , int ) : return ( subject == 1 ) if hasattr ( subject , 'startswith' ) : if ( subject . strip ( ) . lower ( ) in ( 'true' , 'on' , '1' , 'yes' , 'y' ) ) : return True return False
interpret a string as a boolean .