Issue
Say my directory looks like this
folder
⮑ file.py
⮑ class.py
In want to make a function in class.py that can return the filepath of the current file when it is executed in file.py.
I have tried __file__
and os.path.basename/dirname/abspath
but they return the filepath of class.py when I want the filepath of file.py.
How can I get the filepath of file.py from class.py's function?
Solution
Just put the following in your function in class.py
.
import inspect
filename = inspect.stack()[1].filename
Answered By - GooJ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.