python change directory to file location code example
Example 1: change directory in python os
import os
path = "C:\Users\Your\Directory"
os.chdir(path)
Example 2: change directory in python script
os.chdir(os.path.dirname(__file__))
Example 3: os.chdir python
os.chdir("directory name")
Example 4: python set cwd to script directory
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)