Checking if elements are empty

Neil Cerutti horpner at yahoo.com
Mon Sep 10 13:44:02 EDT 2007


On 2007-09-10, Chris Mellon <arkanes at gmail.com> wrote:
> On 9/10/07, Neil Cerutti <horpner at yahoo.com> wrote:
>> Agreed; but I prefer 'if y[0] == ""', absent more context and
>> better names.
>
> Probably should use u"" if you're going to take that route, as
> this will fail spuriously if y[0] contains a unicode string
> that can't be implicitly converted to ascii. Personally, I
> prefer the boolean check and I'll let operations fail elsewhere
> if there's a type mismatch.

I have a quibble not with the functionality of the boolean check,
but with its expressiveness. if y[0] == "" expresses more, i.e.,
that I expect y[0] to contain a Python byte string.

-- 
Neil Cerutti



More information about the Python-list mailing list