python - 每次我在 python 中打印一些东西时,有没有办法打印类/函数名称?

标签 python

在 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/

相关文章:

python - PyQt : Trying to understand graphics scene/view

python - PyQt 类不适用于第二次使用

python - 在 Python 中,如何用列表中的随机项替换字符串中的单词?

python - 如何求和并表示一个 DataFrame 来创建另一个 DataFrame

python - 如何在 Python 中写入/打包二进制字符串到文件

python - 将字符串分成 block ,然后将这些 block 传递给一个新对象。 python 3

python - 使用 pywin32 的可移植 Python com 服务器

python - 当我有两个以太网卡时,如何发送 UDP 广播?

python - 从imdb api下载数据时出现503错误

python - 无法打开带空格的Word文件