Find the current directory and file's directory

To find the current directory in Python, you can use the following code:

import os
current_directory = os.getcwd()
print(current_directory)

Watch a course Python - The Practical Guide

To find the directory of the current file in Python, you can use the following code:

import os
current_file_directory = os.path.dirname(os.path.abspath(__file__))
print(current_file_directory)