Em Dom, 2008-11-02 às 16:26 -0800, William Stein escreveu: > On Sun, Nov 2, 2008 at 4:15 PM, Ronan Paixão <[EMAIL PROTECTED]> wrote: > > > > 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 > > That is unfortunately not equivalent to the unix which command. > For example, if the file phc appears anywhere in the path it will > get included. The which command instead will tell you whether > or not there is an *executable* called phc that is in the path. > So that's a subtle difference. > > -- William
Sure, there some subtle difference that can be overcome with some changes: import os try: filename = [p for p in os.environ['PATH'].split(':') if os.path.exists('%s/%s' % (p,'phc'))] + "/phc" s = os.stat(filename)[0] if not s & 0x49: #sees if at least one exec bit is set #might require more voodoo to see if #the user itself can exec it raise except: raise ValueError, "phc not found" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---