Em Dom, 2008-11-02 às 17:51 -0800, mabshoff escreveu: > > > On Nov 2, 5:32 pm, Ronan Paixão <[EMAIL PROTECTED]> wrote: > > 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 > > It is not sufficient that at least one exec bit is set, it has to be > the right one depending on ownership. I really don't see any benefit > over using "which" - aside from the fact that some versions of which > do not return an error code unequal zero when no binary is found. >
That's exactly what I meant by "might require more voodoo to see if the user itself can exec it". I just sketched the code because doing it in Python might be more portable, but thinking again, you probably won't get exec attributes in non-Unix systems anyway (though I'm not sure how os.stat handles that). However, since porting it to Windows might be a Sage target one day, doing it the "hard way" (which probably should include more thinking) may be desirable. Ronan Paixão > > #might require more voodoo to see if > > #the user itself can exec it > > raise > > except: > > raise ValueError, "phc not found" > > Cheers, > > Michael > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---