Sometimes, we want to run the shell ‘cd’ command to change the working directory with Python.
In this article, we’ll look at how to run the shell ‘cd’ command to change the working directory with Python.
How to run the shell ‘cd’ command to change the working directory with Python?
To run the shell ‘cd’ command to change the working directory with Python, we can call the os.chdir
method.
For instance, we write:
import os
path = './'
os.chdir(path)
to change the current working directory to path
.
Conclusion
To run the shell ‘cd’ command to change the working directory with Python, we can call the os.chdir
method.