What is a Python eq...
Notifications
Clear all

What is a Python equivalent of PHP's var_dump()?

RSS

(@sathish)
Member Moderator
Joined: 1 year ago
帖子:1391
10/05/2021 10:12 am

当debugging in PHP, I frequently find it useful to simply stick avar_dump()in my code to show me what a variable is, what its value is, and the same for anything that it contains.

What is a good Python equivalent for this?


Quote
(@ganesh)
Noble Member
Joined: 1 year ago
Posts: 1362
10/05/2021 10:13 am

The best Python equivalent of PHP'svar_dump()is to combineprintwithvars:

print vars(foo),vars(bar)

Another important method if you want to display the value nicely, you can use thepprintmodule. The easiest way to dump all variables with it.

from pprint import pprint

pprint(globals())

pprint(locals())


ReplyQuote
Share:
Baidu