[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Dont know what my class is called...

Adam W.

2/17/2008 11:07:00 PM

I am using the xml.sax package, and I'm running into a little
problem. When I use the parse(url, ContentHandler()) method, I don't
know what parse() is naming the instance of ContentHandler.

I have a sub-class of ContentHandler make a dictionary of what it
parses, but the problem is I don't know the name of instance for me to
get at it. The only way I have gotten at my dict is to declare it a
global value, and I know that is not the right way to do it.

I though I would be clever and put "print self" inside the __int__
method of the ContentHandler sub-class, in hopes it would display its
given name, but it returned a rather useless: <__main__.FeedHandler
instance at 0x02D8B5D0>

So, any ideas on how to figure this out would be great.
3 Answers

Diez B. Roggisch

2/17/2008 11:12:00 PM

0

Adam W. schrieb:
> I am using the xml.sax package, and I'm running into a little
> problem. When I use the parse(url, ContentHandler()) method, I don't
> know what parse() is naming the instance of ContentHandler.
>
> I have a sub-class of ContentHandler make a dictionary of what it
> parses, but the problem is I don't know the name of instance for me to
> get at it. The only way I have gotten at my dict is to declare it a
> global value, and I know that is not the right way to do it.
>
> I though I would be clever and put "print self" inside the __int__
> method of the ContentHandler sub-class, in hopes it would display its
> given name, but it returned a rather useless: <__main__.FeedHandler
> instance at 0x02D8B5D0>
>
> So, any ideas on how to figure this out would be great.

It's a bit hard to get what you are after, but maybe this solves your
problem?

handler = FeedHandler()

parse(handler)

print handler.my_instance_variable_of_choice

The above assumes that my_instance_variable_of_choice is created +
filled within the handler of course.

Diez

Adam W.

2/17/2008 11:23:00 PM

0

On Feb 17, 6:12 pm, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
> It's a bit hard to get what you are after, but maybe this solves your
> problem?
>
> handler = FeedHandler()
>
> parse(handler)
>
> print handler.my_instance_variable_of_choice
>
> The above assumes that my_instance_variable_of_choice is created +
> filled within the handler of course.
>
> Diez

Doh! I never thought to try that because I assumed parse needed to
initialize it itself or else it would go haywire, probably stemming
from my belief that classes are comprised mostly of smoke and mirrors
and are never to be fully understood ;) Thanks for tip.

Ben Finney

2/17/2008 11:33:00 PM

0

"Adam W." <AWasilenko@gmail.com> writes:

> I am using the xml.sax package, and I'm running into a little
> problem. When I use the parse(url, ContentHandler()) method, I don't
> know what parse() is naming the instance of ContentHandler.

I'm not sure what you're asking. Why do you need to know the internal
name for that parameter?

> I have a sub-class of ContentHandler make a dictionary of what it
> parses, but the problem is I don't know the name of instance for me
> to get at it. The only way I have gotten at my dict is to declare it
> a global value, and I know that is not the right way to do it.

Perhaps this::

handler = ContentHandler()
result = parse(url, handler)

--
\ "All my life I've had one dream: to achieve my many goals." -- |
`\ Homer, _The Simpsons_ |
_o__) |
Ben Finney