Is there a Python equivalent of Tcl's auto_execok?
Maytag Repairman
maytagrepairman at yahoo.com
Fri Dec 24 02:57:45 EST 1999
Thanks. Just in case there wasn't, I had written something similar
(which I fear Deja will garble) just after posting my question.
#-----------------------------------------------------------------------
------
#
# fullPath
#
# Search $PATH for the first occurrence of a file. Return the full
path name
# if found. Otherwise, return None.
#
#-----------------------------------------------------------------------
-------
def fullPath(file):
if os.path.isabs(file) and os.path.isfile(file): # already have
it!
return file
else:
for path in string.splitfields(os.environ['PATH'],os.pathsep):
full_path = os.path.join(path,file)
if os.path.isfile(full_path):
if path == '.': # don't
return './file'
return os.path.abspath(full_path)
else:
return full_path
return None
In article
<02CD1B3C026B41C1.AA67173007592BE4.82A69C8F06BE415B at lp.airnews.net>,
claird at starbase.neosoft.com (Cameron Laird) wrote:
>
> In article <83pf6u$q57$1 at nnrp1.deja.com>,
<maytagrepairman at yahoo.com> wrote:
> >
> >
> >Is there a Python equivalent of Tcl's auto_execok?
> .
> .
> .
> No, to the best of my knowledge. Pythoneers must
> import os, string
> for pth in string.split(os.environ['PATH']):
> fnm = os.path.join(pth, exe)
> if os.path.exists(fnm):
> break
> for themselves, I believe.
>
> Credit Gordon McMillan for this coding.
> --
>
> Cameron Laird <claird at NeoSoft.com>
> Business: http://www.Phaseit.net
> Personal: http://starbase.neosoft.com/~claird/home.html
>
--
Rob Cupples
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list