On Mar 14, 10:25 am, Alexander Schatten <asch...@gmail.com> wrote: > 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
os.path.join(sys.path[0], 'config.txt') If the script and config.txt are in /tmp this will return '/tmp/ config.txt' no matter from which directory you started the script. Mario -- http://mail.python.org/mailman/listinfo/python-list