Answers for "python change cwd directory to file location"

1

python set cwd to file location

import os

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
Posted by: Guest on March-23-2021
2

python change cwd to script directory

os.chdir(os.path.dirname(os.path.abspath(__file__)))
Posted by: Guest on July-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language