相关疑难解决方法(0)

Python:打印变量的名称和值?

在调试时,我们经常会看到如下的print语句:

print x        # easy to type, but no context
print 'x=',x   # more context, harder to type
12
x= 12
Run Code Online (Sandbox Code Playgroud)

如何编写一个函数来获取变量或变量的名称并打印其名称和值?我只对调试输出感兴趣,这不会被合并到生产代码中.

debugPrint(x)    #  or
debugPrint('x')
x=12
Run Code Online (Sandbox Code Playgroud)

python debugging

36
推荐指数
5
解决办法
3万
查看次数

标签 统计

debugging ×1

python ×1