0 votes
1 view
in Python by (26.9k points)

In Python, what commands can I use to find:

  1. the current directory (where I was in the terminal when I ran the Python script), and

  2. where the file I am executing is?

1 Answer

0 votes
by (65.9k points)
edited by

You can use the below-mentioned code to get the full path to the directory a Python file is contained in, write this in that file:-

import os 

dir_path = os.path.dirname(os.path.realpath(__file__))

To know more about this you can have a look at the following video tutorial:-