Coding style
Erik Max Francis
max at alcyone.com
Mon Jul 17 20:46:46 EDT 2006
tac-tics wrote:
> I'm well aware that both of these snippets does the same thing. I'm
> just spouting my opinion that lists and integers are not tests, ...
No, but testing their Boolean nature _is_ a test. Aggregate objects in
Python are true if they are non-empty, and false if they are empty.
That is reasonable, not uncommon a convention, and quite useful for
exactly the situations you were talking about. That convention exists
_so that_ writing::
if aContainer:
... container is not empty ...
is meaningful and convenient. So the answer to the original question
was, "The first one." Feel free to write it the other way with an
explicit test, but it's not Pythonic.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Life is a toy made of glass; it appears to be of inestimable price,
but in reality it is very cheap. -- Pietro Aretino, 1537
More information about the Python-list
mailing list