This question already has an answer here:
In Python, what commands can I use to find:
- the current directory (where I was in the terminal when I ran the Python script), and
- where the file I am executing is?
This question already has an answer here:
In Python, what commands can I use to find:
If you're searching for the location of the currently executed script, you can use
sys.argv[0]
to get the full path.Answer to #1:
If you want the current directory, do this:
If you want just any folder name and you have the path to that folder, do this:
Answer to #2:
Pathlib can be used this way to get the directory containing current script :