- When debugging in PHP, we frequently find it useful to simply stick a var_dump() in our 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?
When debugging in PHP, we frequently find it useful to simply stick a var_dump() in our code to show me what a variable is, what its value is, and the same for anything that it contains.
Table Of Content
- To display a value, you can use the pprint module. The easiest way to dump all variables with it is to do
- 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.
- Here is the usage
and the results
[ad type=”banner”]- You can simply install it using pip:
- Here we use self-written Printer class, but dir() is also good for outputting the instance fields/values.
class Printer:
- The sample of usage:
- In PHP’s var_dump() is pprint() with the getmembers() function in the built-in inspect module:
- The best equivalent to PHP’s var_dump($foo, $bar) is combine print with vars:



-
-
-
-
-
Show Commentseasy explanation
good one
useful
Great
Super