Skip to content
Advertisement

Tag: path

How to know the directory where the python script is called?

Let’s say that I have a python script a.py in /A/B/a.py, and it’s in the PATH environment variable. The current working directory is /X/Y/, and it’s the directory where I call the /A/B/a.py. In a.py, how to detect /X/Y/? I mean, how to know in which directory the python call is made? Answer You can get the current working directory

Find full path of the Python interpreter?

How do I find the full path of the currently running Python interpreter from within the currently executing Python script? Answer sys.executable contains full path of the currently running Python interpreter. which is now documented here

How to use glob() to find files recursively?

This is what I have: but I want to search the subfolders of src. Something like this would work: But this is obviously limited and clunky. Answer pathlib.Path.rglob Use pathlib.Path.rglob from the pathlib module, which was introduced in Python 3.5. If you don’t want to use pathlib, use can use glob.glob(‘**/*.c’), but don’t forget to pass in the recursive keyword

Relative paths in Python [duplicate]

This question already has answers here: How do you properly determine the current script directory? (16 answers) Closed 6 months ago. I’m building a simple helper script for work that will copy a couple of template files in our code base to the current directory. I don’t, however, have the absolute path to the directory where the templates are stored.

Advertisement