Article directory
foreword
I am learning Python recently, but I feel that if the dynamic language does not print the file path and line number, if there is a problem Debugging, unless you are very familiar with the business, you will not be able to find the location of the problem.
Anyway, it's not bad to print
code part
import sys
def ShowMsg(msg):
print (msg,' ',sys._getframe(1).f_code.co_filename,sys._getframe(1).f_lineno)
In fact, it is not difficult, python is suitable for this small function, small but strong.
Tips: Here is the location where the function is executed
demo
# 引用
import Utils.Utils as Utils
Utils.ShowMsg('我来打印')
Results of the
我来打印 D:\workSpace\python\train\test.py 13