How to know/change current directory in Python shell?

PythonServer Side ProgrammingProgramming

You can change directory or cd in Python using the os module. It takes as input the relative/absolute path of the directory you want to switch to.

For example

>>> import os
>>> os.chdir('my_folder')

To know the current working directory or pwd use the os module.

For example

>>> import os
>>> print(os.getcwd())
/home/ayush/qna
raja
Published on 27-Dec-2017 08:09:22
Advertisements