How to get the python executable path from current script?
# -*- coding: utf-8 -*- # python import sys # path of the python program print sys.executable # sample output on Windows C:\Python27\python.exe
How to get the path of current running script?
get it from the __file__ attribute.
# -*- coding: utf-8 -*- # python import os # path of current script print os.path.realpath(__file__) # sample output on Windows c:\Users\h3\my-print-path.py
How to find a module's path?
# -*- coding: utf-8 -*- # python import os print os.__file__ # sample output C:\Python27\lib\os.pyc
see also: Python & Perl: Using Modules/Packages/Library
blog comments powered by Disqus