Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29582

Re: portable way of locating an executable (like which)

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'ideally': 0.04; 'true,': 0.04; '21,': 0.07; 'skip:/ 10': 0.07; 'api': 0.09; 'extension.': 0.09; 'given,': 0.09; 'lawrence': 0.09; 'portable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'splitting': 0.09; 'windows,': 0.09; 'extensions': 0.13; ':-)': 0.13; '22:06,': 0.16; 'portably': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'separator,': 0.16; 'subject:which': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'skip': 0.17; 'typing': 0.17; 'thanks,': 0.18; '>>>': 0.18; 'windows': 0.19; 'variable': 0.20; 'equivalent': 0.20; 'trying': 0.21; 'not,': 0.21; "i'd": 0.22; 'split': 0.23; 'linux': 0.24; 'command': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'ext': 0.27; 'there.': 0.28; 'header:X-Complaints-To:1': 0.28; 'chris': 0.28; 'environment': 0.29; 'piece': 0.29; 'subject:like': 0.29; 'this.': 0.29; "i'm": 0.29; 'fri,': 0.30; 'function': 0.30; 'implement': 0.32; 'file': 0.32; 'anybody': 0.32; 'function.': 0.33; 'to:addr :python-list': 0.33; 'generic': 0.35; 'so,': 0.35; 'doing': 0.35; 'there': 0.35; 'add': 0.36; 'received:org': 0.36; 'but': 0.36; 'wanted': 0.36; 'should': 0.36; 'subject: (': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'skip:o 20': 0.38; 'nothing': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'between': 0.63; 'worth': 0.63; 'afraid': 0.66; 'obvious': 0.71; 'gelonida': 0.84; 'look.': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Gelonida N <gelonida@gmail.com>
Subject Re: portable way of locating an executable (like which)
Date Fri, 21 Sep 2012 01:07:08 +0200
References <k3g0h6$mtr$1@ger.gmane.org> <k3g2t5$ar2$1@ger.gmane.org> <CAPTjJmqDa8OxgnvPqK7X-OQk=4+DNuA8=-z5wAd8Nc_kKNvkRw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host unicorn.dungeon.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0
In-Reply-To <CAPTjJmqDa8OxgnvPqK7X-OQk=4+DNuA8=-z5wAd8Nc_kKNvkRw@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.980.1348182445.27098.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348182445 news.xs4all.nl 6876 [2001:888:2000:d::a6]:56247
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29582

Show key headers only | View raw


On 09/21/2012 12:21 AM, Chris Angelico wrote:
> On Fri, Sep 21, 2012 at 7:47 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> On 20/09/2012 22:06, Gelonida N wrote:
>>>
>>> I'd like to implement the equivalent functionality of the unix command
>>> /usr/bin/which
>>>
>>> The function should work under Linux and under windows.
>>>
>>> Did anybody already implement such a function.
>>
>> Searching found nothing obvious to me :(

I was afraid so, but wanted to be sure
>>
>>> If not, is there a portable way of splitting the environment variable
>>> PATH?
>> With os.sep ?
>
> os.sep is the directory separator, but os.pathsep may be what you
> want.

Thanks,
os.pathsep was the missing piece for portably splitting the searchpath

>  Between that and os.getenv('path') you can at least get the
> directories. Then on Windows, you also need to check out
> os.getenv('pathext') and split _that_ on the semicolon, and try each
> of those as a file extension. I'm not sure whether or not Windows will
> add extensions from pathext if one is given on the command line - for
> instance, if typing "foo.exe" will search for "foo.exe.bat" - but the
> basics are there.
>
For what I am doing I can even skip trying the pathexts, the ext is 
already given, but good to know :-)


> Alternatively, there may be a Win32 API funct5ion that does this.
> Would be worth a look.

Yeah true, but ideally I'd like to avoid platform detection and
just have a generic function.



Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: portable way of locating an executable (like which) Gelonida N <gelonida@gmail.com> - 2012-09-21 01:07 +0200

csiph-web