Get Path of current Script

Alexander Schatten aschatt at gmail.com
Mon Mar 14 05:25:46 EDT 2011


Hi,

could someone help me with a small problem? I wrote a Python script
that does some RegEx... transformations. Now, this script loads some
configuration data from a file located in the same directory:

open ('config.txt', 'r').

However, this only works when I execute the script being in the
directory where the script is locates, because otherwise, of course,
this config file is not found, as the path is relative. Now my
question: is there an easy way (API) to get the directory of the
currently running script? Something along the line of:

open (API.getCurrentPath + 'config.txt', 'r').


thanks a lot,

cheers

Alex



More information about the Python-list mailing list