View Single Post
Old 07-18-2010, 11:55 AM   #19
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,354
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Starson17 View Post
Are there any cases where a datatype comments field can have a len(comments) == 0 and comments != False?

I have a test in the non-custom comments field of:

Code:
if not dest_mi.comments or len(dest_mi.comments) == 0:
I can't recall if I did this, not knowing any better, or if Kovid added it because I didn't. In Python, wouldn't the comments field always be False if its length was zero?
The python manual says:
Quote:
In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.
Thus the first test will return True if the string is None or empty, and therefore obviates the need for the second.

I often use the test 'if str: to test if the string has an 'interesting' value.
chaley is offline   Reply With Quote