First, you need to import from inspect
and os
from inspect import getsourcefile
from os.path import abspath
Next, wherever you want to find the source file from you just use
abspath(getsourcefile(lambda:0))
More Related Contents:
- How can I safely create a nested directory?
- Importing modules from parent folder
- How to config nltk data directory from code?
- Import from sibling directory
- Python not recognising directories os.path.isdir() [duplicate]
- How can I safely create a directory (possibly including intermediate directories)?
- How can I extract the folder path from file path in Python?
- How do I create a directory, and any missing parent directories?
- Find the current directory and file’s directory [duplicate]
- How to use glob() to find files recursively?
- Adding Python to PATH on Windows
- How do I get the full path of the current file’s directory?
- ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL’s are there
- os.makedirs doesn’t understand “~” in my path
- Iterating through directories with Python
- How to get rid of double backslash in python windows file path string? [duplicate]
- How to get only the last part of a path in Python?
- How to select a directory and store the location using tkinter in Python
- Python: import module from another directory at the same level in project hierarchy
- PATH not updated correctly from conda activate in VSCode’s terminal
- Extract a part of the filepath (a directory) in Python
- set pythonpath before import statements
- constructing absolute path with os.path.join()
- Determining Whether a Directory is Writeable
- Find all CSV files in a directory using Python
- Changing the directory where .pyc files are created
- Cannot find the file specified when using subprocess.call(‘dir’, shell=True) in Python
- Finding all paths/walks of given length in a networkx graph
- Python not able to open file with non-english characters in path
- Deleting folders in python recursively