metinsaylan // rogue developer

Python: Get working directory

In order to get current directory of script running, you need to use

To get current directory as a variable in your running script, you need to use realpath on __file__ constant. Please check the code snippet below:

import os
cur_path = os.path.dirname( os.path.realpath(__file__) )

In this snippet; realpath gets full path to the file with symbolic links removed. Afterwards, dirname function extracts directory portion from full file name.

You can check python os.path documentation for further details.

Search Python: Get working directory on Google