Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (47.6k 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 (106k 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:-

Related questions

0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Browse Categories

...