473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dumping an instance

If I want to dump (for debugging) an instance and all
of it's member attributes, what's the simplest way?

print myInstance

just gives a pointer to its location in memory

Thanks!

__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250
Jul 18 '05 #1
2 1373
In article <ma*************************************@python.or g>,
gf gf <un**************@yahoo.com> wrote:
If I want to dump (for debugging) an instance and all
of it's member attributes, what's the simplest way?

print myInstance

just gives a pointer to its location in memory


You need to write a str() method for the class. Alternatively, take a look
at the pprint module.
Jul 18 '05 #2
gf gf wrote:
If I want to dump (for debugging) an instance and all
of it's member attributes, what's the simplest way?

print myInstance

just gives a pointer to its location in memory


Roughly speaking, as a starting point:

from pprint import pformat
def dump(obj):
print repr(obj)
for name in obj.__dict__:
val = getattr(obj, name)
print name, '=', pformat(val)

-Peter
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kamal | last post by:
I am trying to dump a hash using Data::Dumper. I need to quote the keys while dumping. My progarm looks like this use Data::Dumper; $Data::Dumper::Quotekeys = 1; $Data::Dumper::Useqq = 1; ...
3
by: kerri | last post by:
Hi, I need to do a mysqldump of specific inserts, updates & deletes. I read in the docs that I can use -w or --where. Can I do a join? Could someone provide an example? Is there another...
6
by: Greg Brant | last post by:
Hi, how can i backup a table / entire DB and get the index's as well as the data / create table's etc cheers Greg
10
by: ken | last post by:
hello, i'm writing a c program on a linux system. i'm debugging a segmentation fault but i don't want it to dump a core file because the memory footprint of the program is over 300Mb and i don't...
3
by: noleander | last post by:
My Vis C++ program takes forever to exit. Reason: it is dumping potential memory leaks. I like finding leaks once a month, but not every time I run. How do I turn mem leak dumping off? I...
11
by: davids58 | last post by:
I currently create sites using xml and xsl to produce .html files. I'm thinking about using PHP and MySQL instead for performance reasons. Is there a way of using PHP to create a set of .html files...
7
by: gomzi | last post by:
hi, I would like to know the command for dumping stored procedures. Thought that I knew the command and dumped the db using the -R option, only to realise that dumping of procedures had failed...
3
by: Rowan | last post by:
I'm trying to enter data from an array ( eg entry1=(x=>y,a=b), entry2=(x=>y,a=>c)) I'm trying to use place holders to dump the data. It maybe late but I can't get this to work. below is the actual...
7
by: =?KOI8-R?B?7cnU0Q==?= | last post by:
I have a class which I want to save it's data automatically on disc, when it's destroyed. I have following code: from cPickle import dump class __Register(object): def __init__(self):...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.