To determine the current directory location with python

Asked 2 years ago, Updated 2 years ago, 75 views

When you run a Python script from terminal, I want to print the path of the current directory and the path of the executed file. Where are the relevant modules?

python directory

2022-09-21 15:34

1 Answers

os.path contains this information.

import os
print(os.getcwd()) #of the current directory
print(os.path.realpath(_file__))#File
print(os.path.dirname(os.path.realpath(_file__)))#directory where the file is located


2022-09-21 15:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.