python library call equivalent to `which' command

Tim Pinkawa timpinkawa at gmail.com
Mon Jun 29 15:38:54 EDT 2009


On Mon, Jun 29, 2009 at 2:31 PM, Tim Pinkawa<timpinkawa at gmail.com> wrote:
> I am curious about it being slow, though. Is there a faster way to get
> the contents of a directory than os.listdir() or is there a faster way
> to see if an element is in a list other than "x in y"? I believe
> 'which' will terminate once it finds any match, which mine does not,
> but that can be fixed by adding a break after the print.

To answer my own question on this specific case, you could check with
os.access which may be faster. I am still curious, Christian, if your
issue with it being slow was that "os.listdir is slow" or "os.listdir
is slow in this case".



More information about the Python-list mailing list