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
import os
current_directory = os.getcwd()
print(current_directory)
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
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
import os
current_file_directory = os.path.dirname(os.path.abspath(__file__))
print(current_file_directory)