在 Python 中,是否可以在调用“打印”函数时打印“类和函数名”?
例如,
class SimpleClass:
def function1(self):
print "This is the printed msg"
c = SimpleClass()
c.function1()
"Output wanted"
SimpleClass:function1 - "This is the printed msg"
最佳答案
使用logging模块而不是打印语句。
可用属性列表位于 here ,包括:args, asctime, created, exc_info, filename, funcName, levelname, levelno, lineno, module, msecs, message, msg, name, pathname, process, processName, relativeCreated, thread, threadName
。
关于python - 每次我在 python 中打印一些东西时,有没有办法打印类/函数名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29782094/