Inspecting a variable (object) by printing it

python, ruby

Solution

`dir()` will probably give you what you want:

for key in dir(my_obj):
    print('{}: {}'.format(key, getattr(my_obj, key)))

There's a lot more information there that you're expecting though, if I had to guess :)

Problem

In Ruby one can inspect a variable (object) by `p my_obj` so it'll print it as "deep" and in detail as possible. It's useful for logging and debugging. In python I thought it was `print my_obj`, only it didn't print much but `<requests.sessions.Session object at 0x7febcb29b390>` which wasn't useful at all. How do I do this?

Original source

Related problems