Visitor design pattern for python objects?

Magnus L. Hetland mlh at
Tue Nov 23 20:50:10 EST 1999

Nicky <nickysandhu at> writes:

> Is there a visitor type method that exists for all python objects?
> Visitor methods would be useful to allow an apply type functionality
> for objects.
> E.g.
>  base python object has accept method
>  def accept(this,visitor):
>   visitor.visit(this)
>  The visitor than would be called back with the particular type of
> object allowing the python object to delegate behavior to the visitor
> object. Is this already implemented or is there an alternative way of
> doing this?

Wouldn't every subclass have its own accept-method to avoid using the
superclass in the visit-method? (Maybe I have missed some
coercion-rules here...) In that case, each accept-method may have a
visit-method name of a different name, at least... (visitSimpleNode

suspecting-that-i-really-did-misunderstand-that-coercion'ly yours,


> --Nicky


  Magnus          Echelon jamming noise:
  Lie             FBI CIA NSA Handgun Assault Bomb Drug Terrorism
  Hetland         Special Forces Delta Force AK47 Hillary Clinton 

More information about the Python-list mailing list