Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2004, 01:59 AM
NewPythoner NewPythoner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Bombay, India
Posts: 159 NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 43 m 45 sec
Reputation Power: 7
Send a message via Yahoo to NewPythoner
Inside the memory

Hi,

Many a times when we want to view what exactly is present in an object we get................

Code:
<xml.dom.minidom.Document instance at 0x011EDD78>


It does differ for other objects....I wanted to know if there is a way out by which I cld view the info in that object....or maybe at that particular memory location..... is that possible?????

Rgds,
Subha

Reply With Quote
  #2  
Old November 9th, 2004, 06:50 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 10 m 32 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
What we need here is to overload the __repr__ method, or if we want to print the value the __str__ method. Like you mentioned the default representation (inherited from object) returns the objects name and memory address, which isn't exactly useful .

Anyway, this should help you understand these methods and what they're used for:

Code:
>>> class Bar:
...     def __init__(self, foo):
...         self.foo = foo
... 
>>> b = Bar('String Value')
>>> b
<__main__.Bar instance at 0x62210>
>>> 
>>> class Bar:
...     def __init__(self, foo):    
...         self.foo = foo
...     def __str__(self):
...         return str(self.foo)
... 
>>> b = Bar('String Value')
>>> b
<__main__.Bar instance at 0x62440>
>>> print b
String Value
>>> 
>>> class Bar:
...     def __init__(self, foo):
...         self.foo = foo
...     def __str__(self):
...         return str(self.foo) 
...     def __repr__(self):
...         return str(self.foo)
... 
>>> b = Bar('String Value')
>>> b
String Value
>>> print b
String Value
>>>


If you wanted to replace a method in a target class then the easiest way to do this would be to inherit from the target class and overload the methods your interested in [__repr__ and or __str__].

Hope this helps,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old November 10th, 2004, 03:27 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,243 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 5 h 41 m 59 sec
Reputation Power: 265
If you want a list of the attributes on an object you can use dir().

If you want more detailed information you can use the inspect module.

Dave - The Developers' Coach

Reply With Quote
  #4  
Old November 10th, 2004, 04:35 AM
NewPythoner NewPythoner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Bombay, India
Posts: 159 NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 43 m 45 sec
Reputation Power: 7
Send a message via Yahoo to NewPythoner
I guess I've to be more clear with my question here!

Code:
>>> doc="""<?xml version="1.0" encoding="UTF-8"?>
... <verse>
... 	<attribution>Subha</attribution>
... 	<line>I believe in angels something good in evrything I see</line>
... </verse>
... """
>>> from xml.dom import minidom
>>> doc_node=minidom.parseString(doc)
>>> doc_node
<xml.dom.minidom.Document instance at 0x011BF710>


So this is the problem. Not a big one though, but wld like to know the content of doc_node. How do I do that???

Rgds,
Subha

Reply With Quote
  #5  
Old November 10th, 2004, 05:33 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
A quick search of the Python website would have revealed to you the XML sig and it's documentation:
http://pyxml.sourceforge.net/topics/howto/xml-howto.html

grim
__________________
*** Experimental Python Markup CGI V2 ***

Last edited by Grim Archon : November 10th, 2004 at 05:35 AM.

Reply With Quote
  #6  
Old November 10th, 2004, 05:44 AM
NewPythoner NewPythoner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Bombay, India
Posts: 159 NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 43 m 45 sec
Reputation Power: 7
Send a message via Yahoo to NewPythoner
What shd I say...unfortunately I'm a member of the XML SIG but then I still have not got my first query answered!

And anyway, I guess my question remains same for other objects which produce the same kind of output on screen...not just the XML objects....let it pass!!

Thanks,
Subha

Reply With Quote
  #7  
Old November 10th, 2004, 05:46 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
http://diveintopython.org/xml_processing/parsing_xml.html
has a walk through.

If you still have problems get back to us

Reply With Quote
  #8  
Old November 10th, 2004, 05:51 AM
NewPythoner NewPythoner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Bombay, India
Posts: 159 NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 43 m 45 sec
Reputation Power: 7
Send a message via Yahoo to NewPythoner
Thanks Grim! I'm going thru' that too....will get back if my doubts still exist!

Thanks,
Subha

Reply With Quote
  #9  
Old November 10th, 2004, 09:31 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
When you get something like:
<xml.dom.minidom.Document instance at 0x011EDD78>
or a some other such statement all you can say is that it is a reference to an object - unless you recognise the object you cannot possibly know how that object is structured internally.

The object might be an xml thingy, equally it could be a reference to a regular expression match or an instance of a C extension module. These objects are not related in any way and their internal structure is totally different. So dissecting these objects in a generic way is unlikely to be useful.

Reply With Quote
  #10  
Old November 11th, 2004, 04:43 AM
NewPythoner NewPythoner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Bombay, India
Posts: 159 NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level)NewPythoner User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 43 m 45 sec
Reputation Power: 7
Send a message via Yahoo to NewPythoner
Thanks Grim Its clear!

Subha

Reply With Quote
  #11  
Old November 11th, 2004, 12:09 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
You can view the methods/attributes of any object using the dir() command.
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Inside the memory


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |