I want to execute a python script from a certain directory and want to change the working directory for the execution without cd
-ing in the shell or script. Is there a way to do this with the regular Python 3 interpreter?
Say I'm in the directory cwd
and there is a script baz.py
in a sub(sub)directory that I want to execute.
cwd/foo/bar/baz.py
Is it possible to tell the interpreter to use any directory among cwd
, foo
, bar
(or anywhere else in the filesystem) as the working directory where the script is executed? IDEs can do this in run configurations, what's the simplest way to achieve it without actually cd
-ing into the other directory?
EDIT: I know how to change the directory from within the script, but I'm looking for a way to tell the interpreter where to execute it without modifying the script itself.