Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29589
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'skip:/ 10': 0.07; 'fname': 0.09; 'portable': 0.09; 'sep': 0.09; 'splitting': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'subject:which': 0.16; 'variable.': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'windows': 0.19; 'variable': 0.20; 'equivalent': 0.20; 'not,': 0.21; "i'd": 0.22; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'linux': 0.24; 'command': 0.24; 'machine': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; 'besides': 0.27; 'environment': 0.29; '(maybe': 0.29; '(since': 0.29; 'subject:like': 0.29; 'function': 0.30; 'implement': 0.32; 'anybody': 0.32; 'mac': 0.32; 'directory,': 0.33; 'function.': 0.33; 'know.': 0.33; 'described': 0.35; 'jason': 0.35; 'path': 0.35; 'pm,': 0.35; 'there': 0.35; 'but': 0.36; 'should': 0.36; 'subject: (': 0.36; 'two': 0.37; 'ones': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'sure': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'more': 0.63; '20,': 0.65; 'search,': 0.65; 'header:Reply-To:1': 0.68; 'believe': 0.69; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'gelonida': 0.84; 'write:': 0.91 |
| Date | Thu, 20 Sep 2012 22:31:17 -0400 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 |
| MIME-Version | 1.0 |
| To | Jason Swails <jason.swails@gmail.com> |
| Subject | Re: portable way of locating an executable (like which) |
| References | <k3g0h6$mtr$1@ger.gmane.org> <CAEk9e3rfcvbrjVpTUmX9RdtmpExe_owxfrEwJqDREzfUmNGR0w@mail.gmail.com> |
| In-Reply-To | <CAEk9e3rfcvbrjVpTUmX9RdtmpExe_owxfrEwJqDREzfUmNGR0w@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:YE+vmp4DatnvJebgSt6uOjkQ2fO+xUnCTtqCo0PUIgX TV7StiYRpHGhWf9QbweZpnQeAy4VYNdTaI/UKDehOzUoTpwlL0 acdpAzrmWSTVNb4QmxVKTjnfJl1caLuJgletIllGuJ8SQ8ecpw 3CLlivmkfnprwqFuCWZW4Nd5+jy/VrZWlVqbx7QWoQ6Adumpoj Ztsj8L8lqzaIdARsPk+/7TPwEjaNrvIREEzYcgv4H3Sykh0OfX K3aLSIG304r1vanBzlug3cp6Wz5RaLchFByqLZkbSCl7x7nUxt gn/azEABTArfF5FyLSiHhsCSjvhOvPHLfkDWwwXITMVVDWt9g= = |
| Cc | Gelonida N <gelonida@gmail.com>, python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | d@davea.name |
| 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.985.1348194714.27098.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1348194714 news.xs4all.nl 6842 [2001:888:2000:d::a6]:37188 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:29589 |
Show key headers only | View raw
On 09/20/2012 06:04 PM, Jason Swails wrote:
> On Thu, Sep 20, 2012 at 5:06 PM, Gelonida N <gelonida@gmail.com> 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.
>> If not, is there a portable way of splitting the environment variable PATH?
>>
> I've used the following in programs I write:
>
> def which(program):
> def is_exe(fpath):
> return os.path.exists(fpath) and os.access(fpath, os.X_OK)
>
> fpath, fname = os.path.split(program)
> if fpath:
> if is_exe(program):
> return program
> else:
> for path in os.getenv("PATH").split(os.pathsep):
> exe_file = os.path.join(path, program)
> if is_exe(exe_file):
> return exe_file
> return None
>
> IIRC, I adapted it from StackOverflow. I know it works on Linux and Mac OS
> X, but not sure about windows (since I don't know if PATH works the same
> way there).
>
I don't have a Windows machine set up right now, but I believe there are
two more directories to search, besides the ones described in the PATH
variable.
One is the current directory, and the other is the Windows directory
(maybe also the xxx/system32 or something).
They don't have analogues in Linux or Mac, as far as I know.
--
DaveA
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: portable way of locating an executable (like which) Dave Angel <d@davea.name> - 2012-09-20 22:31 -0400 Re: portable way of locating an executable (like which) Hans Mulder <hansmu@xs4all.nl> - 2012-09-21 12:13 +0200
csiph-web