Posts: 4,646
Threads: 1,493
Joined: Sep 2016
i'm often dealing with an object that apparently is in a different state than expected. i run into this a few times and have to add and change a lot of code to figure it out. i'd like to just dump everything out so i can see the object when debugging. when i use
repr()
on it i often just get something like
'<foo object at 0x0123456789ab>'
. is there anything better than
repr()
for this?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
Jun-01-2019, 06:27 AM
(This post was last modified: Jun-01-2019, 06:27 AM by Skaperen.)
i have already written a big function called print_object(). i think i just need to add more things to it, like support for attributes. it was an early project. it probably has a lot of bad code. i should, also, clean it up.
the purpose of print_object was to produce output that is easy to read and is valid Python code that can recreate the object. i would probably have to abandon recreatability to support attributes, since a literal cannot usually set these. it is recursive and explodes each referenced object. every leaf item is printed on a separate line. strings are showed with a slice at the end that yields the whole string with its actual length as a way to quickly see how long the string is. dictionaries are shown with keys sorted for human convenience. i think sets are sorted, too. it was originally written for Python 2 and has been tweaked to get it working on Python 3.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.