python library call equivalent to `which' command

2009-06-29 Thread destroooooy
Hi, I'm looking for a Python library function that provides the same functionality as the `which' command--namely, search the $PATH variable for a given string and see if it exists anywhere within. I currently examine the output from `which' itself, but I would like something more portable. I

Re: python library call equivalent to `which' command

2009-06-29 Thread Tim Pinkawa
On Mon, Jun 29, 2009 at 12:54 PM, destroydestrooo...@gmail.com wrote: Hi, I'm looking for a Python library function that provides the same functionality as the `which' command--namely, search the $PATH variable for a given string and see if it exists anywhere within. I currently examine

Re: python library call equivalent to `which' command

2009-06-29 Thread Tim Golden
Tim Pinkawa wrote: On Mon, Jun 29, 2009 at 12:54 PM, destroydestrooo...@gmail.com wrote: Hi, I'm looking for a Python library function that provides the same functionality as the `which' command--namely, search the $PATH variable for a given string and see if it exists anywhere within. I

Re: python library call equivalent to `which' command

2009-06-29 Thread Christian Heimes
Tim Pinkawa wrote: def which(file): for path in os.environ[PATH].split(:): if file in os.listdir(path): print %s/%s % (path, file) if file in os.list() is slow and not correct. You have to check if the file is either a real file or a symlink to a file and

Re: python library call equivalent to `which' command

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 13:53:30 -0500, Tim Pinkawa wrote: I'm looking for a Python library function that provides the same functionality as the `which' command--namely, search the $PATH variable for a given string and see if it exists anywhere within. I currently examine the output from `which'

Re: python library call equivalent to `which' command

2009-06-29 Thread Robert Kern
On 2009-06-29 14:31, Tim Pinkawa wrote: On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimesli...@cheimes.de wrote: if file in os.list() is slow and not correct. You have to check if the file is either a real file or a symlink to a file and not a directory or special. Then you have to verify that

Re: python library call equivalent to `which' command

2009-06-29 Thread Christian Heimes
Tim Pinkawa wrote: I realize four lines of Python does not replicate the functionality of which exactly. It was intended to give the original poster something to start with. Agreed! I am curious about it being slow, though. Is there a faster way to get the contents of a directory than

Re: python library call equivalent to `which' command

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 14:31:25 -0500, Tim Pinkawa wrote: if file in os.list() is slow and not correct. You have to check if the file is either a real file or a symlink to a file and not a directory or special. Then you have to verify that the file has the executable bit, too. I realize four

Re: python library call equivalent to `which' command

2009-06-29 Thread Scott David Daniels
Robert Kern wrote: On 2009-06-29 14:31, Tim Pinkawa wrote: On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimesli...@cheimes.de wrote: if file in os.list() is slow and not correct. You have to check if the file is either a real file or a symlink to a file and not a directory or special. Then you

Re: python library call equivalent to `which' command

2009-06-29 Thread Trent Mick
destroy wrote: Hi, I'm looking for a Python library function that provides the same functionality as the `which' command--namely, search the $PATH variable for a given string and see if it exists anywhere within. I currently examine the output from `which' itself, but I would like

Re: python library call equivalent to `which' command

2009-06-29 Thread MRAB
Tim Pinkawa wrote: On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimesli...@cheimes.de wrote: if file in os.list() is slow and not correct. You have to check if the file is either a real file or a symlink to a file and not a directory or special. Then you have to verify that the file has the