finding real $0

Robin Becker robin at jessikat.demon.co.uk
Fri Apr 21 07:05:56 EDT 2000


In message <20000421124817.C11481 at xs4all.nl>, Thomas Wouters
<thomas at xs4all.net> writes

That's what I need :)
>On Fri, Apr 21, 2000 at 10:55:26AM +0100, Robin Becker wrote:
>
>> Is there any pythonic way to locate the original argument zero of the
>> process? I mean the location of python itself not the script. This would
>> allow me to launch subscripts without having to rely on the path being
>> set up correctly.
>
>Use 'sys.executable':
>
>centurion:~ > python
>>>> import sys 
>>>> sys.executable
>'/usr/bin/python'
>
>centurion:~ > ln -s /usr/bin/python penguin-on-the-telly
>centurion:~ > ./penguin-on-the-telly 
>>>> import sys
>>>> sys.executable
>'./penguin-on-the-telly'
>
>It behaves the same way in a script (it returns the python executable
>started, not the script.) Dont forget about relative paths though, if you
>are going to do stuff based on sys.executable. You probably want to get the
>cwd at the earliest possible moment, and translate sys.executable into an
>absolute path.
>

-- 
Robin Becker




More information about the Python-list mailing list