python __ file__ Is not defined solution
__ file__ It is a variable generated when Python module is imported__ file__ Can’t be used, but what should I do to get the path of the current file
Method 1
import inspect, os.path
filename = inspect.getframeinfo(inspect.currentframe()).filename
path = os.path.dirname(os.path.abspath(filename))
Method 2
import inspect
import os
os.path.abspath(inspect.getsourcefile(lambda:0))