To determine the current directory location with python

Asked 1 years ago, Updated 1 years ago, 64 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.