Skip to content

Get Directory of the current python script

twitter logo github logo ・1 min read  

using Python os module, we can get the current directory of python scripts and change the directory. The os module is included in the standard library, so no additional installation is required. This module provides a portable way of using operating system dependent functionality.

Here the following contents will be described.

Get the current working Directory
os.getcwd() returns the absolute path of the working directory where python is currently running as a string.

import os
currentDirectory = os.getcwd()
print("Current Working Directory")

Change the current working directory
We use chdir() to change the directory.

import os
print("Directory Changed")

I hope this will help you to understand about directories and python.

twitter logo DISCUSS
Classic DEV Post from Feb 20

Career Progression: What Does It Mean to You?

Does your organisation have a plan for career progression? Do you know the steps you need to take to level up?

Aasik Muththalif profile image
Passionate about education, Python, Java, Data Science and code art. looking forward to connect with like minded people.