0 votes
1 view
in Python by (47.7k 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 (107k 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

+1 vote
2 answers
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...