A = os.path.join(os.path.dirname(__file__), '..') # A is the parent directory of the directory where program resides. B = os.path.dirname(os.path.realpath(__file__)) # B is the canonicalised (?) directory where the program resides. C = os.path.abspath(os.path.dirname(__file__)) # C is the absolute path of the directory where the program resides.
Here is what the above code is Doing:
1. __file__ is a global variable that contains the path to the current file.
2. os.path.dirname(__file__) returns the directory of the current file.
3. os.path.realpath(__file__) returns the canonical path of the current file.
4. os.path.abspath(os.path.dirname(__file__)) returns the absolute path of the current file.