Finding the Process Path

Peck, Jon peck at spss.com
Mon Oct 3 10:42:39 EDT 2005


Problem solved, but sys.executable seems to be (mostly) what I need.  The context here is that my code is embedded in another process, so the Python interpreter is not the process executable, and in fact argv is not set (for various reasons not related to Python.)

If I run this code directly through the interpreter, of course Python is what I get from sys.executable.

-----Original Message-----
From: python-list-bounces+jkpeck=aya.yale.edu at python.org [mailto:python-list-bounces+jkpeck=aya.yale.edu at python.org] On Behalf Of Steve Holden
Sent: Monday, October 03, 2005 9:26 AM
To: python-list at python.org
Subject: Re: Finding the Process Path

Peck, Jon wrote:
> Thanks, but this doesn't tell me what I am looking for.
> 
> I am looking for the path for the current process (which will not be the Python interpreter).
> 
Actually the core image will be that of the Python interpreter.

> I see, though, that this is available as sys.executable
> 
The interpreter? That's correct.

What you probably want is

import os, sys
print os.path.abspath(sys.argv[0])

this will give you the path to the Python script the interpreter is running.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list