Steven D'Aprano schreef:
> If seq can be None as well as a sequence, doing a test "if len(seq) > 0"
> won't save you because len(None) will fail. You need an explicit test
> for seq being None:
>
> if seq is not None and len(seq) > 0
>
> Or even better:
>
> if seq
>
> which Just Works regardles
On Tue, 11 Jul 2006 19:43:57 +, Roel Schroeven wrote:
> I know that that is the consensus, and I mostly the form without len(),
> but somehow I still feel it is not as explicit. In
>
> if seq:
>
> there is no distinction between seq is None on the one hand and seq
> being a valid empty seq
Interesting replies, thank you all.
Since the language defines the bahviour, I'm all for using it (when
appropriate).
> there is no distinction between seq is None on the one hand and seq
> being a valid empty sequence on the other hand.
>
> I feel that that is an import distinction, and it's the
Simon Forman schreef:
> I've been programming in python for years and I've always used this
> form
>
> if not seq:
> if seq:
>
> rather than the other and never had any problems.
>
> Anyone presenting arguments in favor of the len() form is IMHO, not
> "getting it". AFAIK, python is not "smart"
horizon5 wrote:
> Hi,
>
> my collegues and I recently held a coding style review.
> All of the code we produced is used in house on a commerical project.
> One of the minor issues I raised was the common idiom of specifing:
>
>
> if len(x) > 0:
> do_something()
>
> Instead of using the langua
Le mardi 11 juillet 2006 13:52, horizon5 a écrit :
> Arguments that have been presented for using len(x) > 0 to
> test emptiness of a container include:
> - It's safer
> - Not relying on weird behaviour of the language
> - Explicit is better than implicit (as stated by 'this' module, Zen
> of
horizon5 wrote:
> Hi,
>
> my collegues and I recently held a coding style review.
> All of the code we produced is used in house on a commerical project.
> One of the minor issues I raised was the common idiom of specifing:
>
>
> if len(x) > 0:
> do_something()
>
> Instead of using the lang
On Tue, 11 Jul 2006 04:52:42 -0700, horizon5 wrote:
> Hi,
>
> my collegues and I recently held a coding style review.
> All of the code we produced is used in house on a commerical project.
> One of the minor issues I raised was the common idiom of specifing:
>
>
> if len(x) > 0:
> do_somet
horizon5 wrote:
> Hi,
>
> my collegues and I recently held a coding style review.
> All of the code we produced is used in house on a commerical project.
> One of the minor issues I raised was the common idiom of specifing:
>
>
> if len(x) > 0:
> do_something()
>
> Instead of using the lang
Hi,
my collegues and I recently held a coding style review.
All of the code we produced is used in house on a commerical project.
One of the minor issues I raised was the common idiom of specifing:
if len(x) > 0:
do_something()
Instead of using the language-defined bahviour, as stated by PE
10 matches
Mail list logo