Dont know what my class is called...

A

Adam W.

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.
 
D

Diez B. Roggisch

Adam said:
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
 
A

Adam W.

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.
 
B

Ben Finney

Adam W. said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top