Creating a list of files in a directory

Fredrik Lundh fredrik at pythonware.com
Wed Nov 7 20:21:21 CET 2001


Jeff Klassen wrote:
> for allfiles in workingdir:
>     matchedfile=filespec.search(allfiles)
>     if matchedfile > 0:

no, no, no: None isn't a number (and neither are match
objects), and to quote the language reference:

    objects of different types always compare unequal,
    and are ordered consistently but arbitrarily

consider this:

Python 2.0 (#8, Jan  4 2001, 12:33:41)
>>> None > 0
1

Python 2.2b1 (#25, Oct 19 2001, 21:26:51)
>>> None > 0
0

assuming you don't really want arbitrary behaviour, you
better leave that "> 0" out.

</F>





More information about the Python-list mailing list