Accessing 'mangled' class attrbutes
sjuranic at gmail.com
Wed Mar 1 17:22:51 CET 2006
Gerard Flanagan wrote:
> I would like to do the following:
> from elementtree.SimpleXMLWriter import XMLWriter
> class HtmlWriter(XMLWriter, object):
> def write_raw(self, text):
> super( HtmlWriter, self ).flush()
> super( HtmlWriter, self ).__write(text)
> but because of the name-mangling caused by '__write' I get:
> AttributeError: 'super' object has no attribute '_HtmlWriter__write'.
> Is there any simple way round this situation in general?
> (I just want to write out a HTML 'DOCTYPE' declaration)
Try: (not the Python keyword, but a directive to you)
In general, to access the name-mangled members, simply add
_<class_name> to the front of the member name and you should be able to get
at it. But be careful, since this is a reference to the base class, so if
it's inherited from some other class, you'll need to know from which class
the member is inherited.
More information about the Python-list