How to find the current directory of the script file in Python?

If you want to find the current directory of the Python script file, use the getcwd() method from the os module. os.getcwd() method returns the path of current working directory in string data type. Here is an example.

import os

current_directory = os.getcwd()

print(current_directory)
find the current directory of the script file in Python

More tips on files

Reference

  • More about getcwd() method and files and directories in os module at Python docs.


Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.