1import os
2
3# To get absolute path to current script
4absolutePath = os.path.realpath(__file__)
5print(absoultePath) # c:\File\Path\to\Current\Script.py
6
7# To get absolute path excluding file name
8directory = ("//".join(os.path.realpath(__file__).split('//')[:-1]))
9print(directory) # c:\File\Path\to\Current split('\\') for windows
1from os import getcwd # only import "getcwd" from os
2
3getcwd() # Get the current working directory