Locate python home

Mike C. Fletcher mcfletch at rogers.com
Wed Feb 25 05:00:36 EST 2004


Thomas Aanensen wrote:

>>import sys
>>print sys.executable
>>    
>>
>
>Thanks, but there is still one problem:
>
>This leads to the path C:\python\Python23\pythonw.exe. In my application I
>cannot use pythonw.exe, I need python.exe (console reasons). Is there some
>way to get this instead?
>
>If not, would it be ok to assume that python.exe will always reside in the
>same directory as pythonw.exe?
>  
>
Never trust the assumption:

 >>> import os
 >>> os.path.isfile( os.path.join(os.path.dirname( sys.executable ), 
'python.exe' ))
False

(This is from within Pythonwin, which has its executable elsewhere). 

It's a good idea to check and see if the file really does exist.  If it 
doesn't, either raise an error to tell the user to figure out what's 
wrong, or use the executable as given, (possibly checking/raising the 
error *only* if the executable is named pythonw and you can't find the 
python executable, though that would still have you running PythonWin in 
the above example (checking for "not named python" would be safer)).

Anywho, have fun,
Mike

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/






More information about the Python-list mailing list