This is my debug.py:
这是我的debug.py:
class Debug:
@classmethod
def file_name(self):
import os
return os.path.basename(__file__)
this is my test.py:
这是我的test.py:
print Debug.file_name()
This will print debug.py while I want to get test.py. What should I do?
这将打印debug.py,而我想获得test.py.我该怎么办?
1 个解决方案
#1
0
You can use inspect.stack
:
你可以使用inspect.stack:
import inspect
import os
class Debug:
@classmethod
def file_name(self):
caller = inspect.stack()[1]
return os.path.basename(caller[1])
#1
0
You can use inspect.stack
:
你可以使用inspect.stack:
import inspect
import os
class Debug:
@classmethod
def file_name(self):
caller = inspect.stack()[1]
return os.path.basename(caller[1])