Extending objects by a method?

Karsten Wutzke kwutzke at web.de
Thu Jul 15 07:35:06 EDT 2010


Hello,

I'm new to Python so beware.

I have a hierarchical object structure which I iterate over (the
elements/classes of interest). I would like to apply the Visitor
pattern onto this object structure, so I must add an "accept" method
to every object (I'm interesting in) for the Visitor pattern to work.

Is there any Python-inbuilt way to dynamically add a method or do I
have to wrap each iterated object into a Decorator supplying the
accept method? The latter would mean having to rebuild the (part)
hierarchy with the Decorator objects before running the Visitor, which
I'd like to avoid.

Karsten



More information about the Python-list mailing list