What is a Python equivalent of PHP's var
This question already has an answer here:
To display a value nicely, you can use the pprint module. The easiest way to dump all variables with it is to do
from pprint import pprint
pprint(globals())
pprint(locals())
If you are running in CGI, a useful debugging feature is the cgitb module, which displays the value of local variables as part of the traceback.
我认为与PHP的var_dump($foo, $bar)
最相当的结合print
和vars
:
print vars(foo),vars(bar)
与PHP的var_dump()
最接近的是pprint()
和内置的inspect
模块中的getmembers()
函数:
from inspect import getmembers
from pprint import pprint
pprint(getmembers(yourObj))
链接地址: http://www.djcxy.com/p/69180.html
上一篇: 我如何调试PHP WSOD?
下一篇: 什么是PHP的变种Python的等价物