xxxxxxxxxx
import os
#full path
dir_path = os.path.dirname(os.path.realpath(__file__))
#current dir
cwd = os.getcwd()
xxxxxxxxxx
>>> import os
>>> path=os.path.dirname("C:/folder1/folder2/filename.xml")
>>> path
'C:/folder1/folder2'
>>> os.path.basename(path)
'folder2'
xxxxxxxxxx
import os
your_file_path = "D:\\your\\dir\\path\\file.csv"
print(f"Dir:{os.path.dirname(your_file_path)}")
#>>> Dir:D:\\your\\dir\\path
xxxxxxxxxx
from os import getcwd
print(getcwd())
#This prints the directory like C:\users\hp\projects
xxxxxxxxxx
from os import getcwd # only import "getcwd" from os
getcwd() # Get the current working directory
xxxxxxxxxx
import os.path
from os import path
def main():
print ("Is it File?" + str(path.isfile('guru99.txt')))
print ("Is it File?" + str(path.isfile('myDirectory')))
if __name__== "__main__":
main()