Testing if a list exist

Aahz Maruch aahz at panix.com
Thu Dec 21 16:36:11 CET 2000


In article <3A421FA8.61A49D48 at hotmail.com>,
joonas  <keisari_ at hotmail.com> wrote:
>
>How can I test if a list exists or not.

Based on the code you're using, it seems more that you're trying to test
whether a variable of a specific name exists, rather than testing to see
whether that variable contains a list.  I'd recommend setting the value
of the variable to None before you want to start using it; later on, you
can just say

if foo:

and go on from there.  That's assuming foo will only contain a list; if
it might contain something other than a list, use the types module or code
like this:

if type(foo) == type([]):
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

I don't really mind a person having the last whine, but I do mind
someone else having the last self-righteous whine.  --Aahz



More information about the Python-list mailing list