Dont know what my class is called...

Diez B. Roggisch deets at nospam.web.de
Sun Feb 17 18:12:22 EST 2008


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



More information about the Python-list mailing list