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 Heimes 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

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 something

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 Heimes 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

Re: python library call equivalent to `which' command

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 21:53:42 +0200, Christian Heimes 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 termin

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 reali

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 o

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 Heimes 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 t

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

Re: python library call equivalent to `which' command

2009-06-29 Thread Tim Pinkawa
On Mon, Jun 29, 2009 at 2:31 PM, Tim Pinkawa 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 f

Re: python library call equivalent to `which' command

2009-06-29 Thread Tim Pinkawa
On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimes 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 fou

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

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, 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 o

Re: python library call equivalent to `which' command

2009-06-29 Thread Tim Pinkawa
On Mon, Jun 29, 2009 at 12:54 PM, 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 `

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 loo