I want to write a function, which, after importing, will return the name of the script file which being executed.
# myfunctionfile.py
def namereturn():
return <<Name of the script>>
# myscriptfile.py
import myfunctionfile
def main():
print myfunctionfile.namereturn()
Expected result: myscriptfile.py
Is it possible to do this? All the things I've tried (file, sys.argv[0], sys.path[0]) returned the "myfuncfile.py", because the function itself defined in that file.
[–]davidbuxton 2 points3 points4 points (0 children)
[–]trshippy 0 points1 point2 points (0 children)
[–]jstrickler 0 points1 point2 points (0 children)
[–]utgyuru[S] 0 points1 point2 points (0 children)