python - Print the current footprint of arbitrary objects -


i looking way print out current state of object.

i want include variables declared using self (note: not want see methods, or other information on object). using this:

def __str__(self):     return str(', '.join("%s: %s" % (str(s), str(self.__dict__.get(s))) s in self.__dict__)) 

in words:

  • i loop on object's __dict__
  • for each value, create tuple consists of str(key) , str(value)
  • the resulting tuple joined in string of following format: "key:value, key:value, ..."

my question is, there more convenient way? obviously, uses __str__ method , may want change behavior serve purpose.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -