don't know if this is "the right"(tm) way to do it, but it seems more
pythonic:

import os
[p for p in os.environ['PATH'].split(':') if os.path.exists('%s/%s' %
(p,'phc'))]

which should return a list with the paths in which the file 'phc'
exists, or an empty list if it doesn't

Ronan Paixão

Em Dom, 2008-11-02 às 14:32 -0800, Craig Citro escreveu:
> > But I would highly suggest that someone (i.e. you) make phc detection
> > much more robust. "which" usually returns an error code unequal to
> > zero (it doesn't on Solaris :(), so that is what you should check and
> > otherwise throw a proper exception.
> >
> 
> So I ended up doing something like this on #4386, but I'd be really
> curious if there's a better way. In particular, here's what I did:
> 
> find_phc = os.popen2('which phc')[1].readlines()
> if find_phc == []:
>     raise ValueError, "phc not found"
> 
> The popen2 returns a pair of file handles, the first wrapping stdin,
> and the second wrapping stdout. (In fact, looking at this, I realize
> that I forgot to close these file handles ... patch up at #4428.)
> 
> So is there a better way to search your path for an executable in Python?
> 
> -cc
> 
> > 


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to