What is a Python equivalent of PHPs var_dump()?
What is a Python equivalent of PHPs var_dump()?
I think the best equivalent to PHPs var_dump($foo, $bar)
is combine print
with vars
:
print vars(foo),vars(bar)
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.
What is a Python equivalent of PHPs var_dump()?
The closest thing to PHPs var_dump()
is pprint()
with the getmembers()
function in the built-in inspect
module:
from inspect import getmembers
from pprint import pprint
pprint(getmembers(yourObj))