py-spy
py-spy copied to clipboard
get str representation of complex types
Hi,
when using dump
subcommand, under the Arguments
and Locals
section, for complex types i can see the class and the memory address, eg:
Locals:
obj: None
abc: <Series at 0x7f996f45eba8>
xyz: <DataFrame at 0x7f996f456940>
It's doable to view the string representation of this complex objects? Thanks.
See https://github.com/benfred/py-spy/issues/451
So, according to this reply it's not possible for types like datetime or other that doesn't have __dict__
property, or i'm missing something?
It can be done, but it'll require writing custom parsers for the binary, in-memory structure of those objects (as I have mentioned in that comment, "custom parsers must be written").
For example, datetime
is represented by a PyDateTime_DateTime
object. Its ->ob_type.tp_name
is set to datetime.datetime
IIRC.
So, you could write a parser that reads an object's ->ob_type.tp_name
, then per "__dict__
-less type" you wish to support, write a parser and call the appropriate one based on the tp_name
. If it's datetime.datetime
you can read the PyDateTime_DateTime
struct and parse it accordingly.
It's definitely much more work then simply displaying the __dict__
, though :(