21 January 2005 6 comments Python
In recent code in the IssueTrackerProduct I needed to have a cgi parameter called
remember-filterlogic so the URL might look like this:
ListIssues?rememeber-filterlogic=no&Filterlogic=show. Because I want the cgi parameters to look human I had to write the following little utility function:
def niceboolean(value): falseness = ('','no','off','false','none','0', 'f') return str(value).lower().strip() not in falseness
It basically converts what you say to what you mean. In Python "f" is a one letter string and would normally mean
True, but since humans are involved here it from means something else for a moment. What do you think?
UPDATE: The code has changed since the comment below by Ben Young. The code had a missing
not which made the code return True on
Off and False on
UPDATE 2: The emptystring "" is now also False.