xxxxxxxxxx
import os
os.path.abspath(__file__) # Directory of current python script
#Output will look something like: C:\Users\UserName\Desktop\py-script.py
Path(__file__).cwd()
xxxxxxxxxx
from pathlib import Path
Path(__file__).cwd()
at the moment I use python 3.10.2 and it works
Pathlib vs OS
The os module represents paths as strings with which you cannot do much. The pathlib module represents paths as special objects with useful methods and attributes.