Old topic, but worth a try.
Here is a simple and efficient var_dump function:
def var_dump(var, prefix=''):
"""
You know you're a php developer when the first thing you ask for
when learning a new language is 'Where's var_dump?????'
"""
my_type = '[' + var.__class__.__name__ + '(' + str(len(var)) + ')]:'
print(prefix, my_type, sep='')
prefix += ' '
for i in var:
if type(i) in (list, tuple, dict, set):
var_dump(i, prefix)
else:
if isinstance(var, dict):
print(prefix, i, ': (', var[i].__class__.__name__, ') ', var[i], sep='')
else:
print(prefix, '(', i.__class__.__name__, ') ', i, sep='')
Sample output:
>>> var_dump(zen)
[list(9)]:
(str) hello
(int) 3
(int) 43
(int) 2
(str) goodbye
[list(3)]:
(str) hey
(str) oh
[tuple(3)]:
(str) jij
(str) llll
(str) iojfi
(str) call
(str) me
[list(7)]:
(str) coucou
[dict(2)]:
oKey: (str) oValue
key: (str) value
(str) this
[list(4)]:
(str) a
(str) new
(str) nested
(str) list