W3docs

Find the current directory and file's directory

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

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

Find the current directory in Python using the os.getcwd method

python— editable, runs on the server
Info

Watch a video course: Python - The Practical Guide

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

Find the directory of the current file in Python using os.path object

python— editable, runs on the server