Getting in to metaprogramming

Aaron Brady castironpi at gmail.com
Fri Nov 28 20:29:04 EST 2008


On Nov 27, 9:28 pm, "Hendrik van Rooyen" <m... at microcorp.co.za> wrote:
>  "Aaron Brady" <castiro... at gmail.com> wrote:
...
> >As you can see, the 'visit' method is mechanical for classes A and B.
> >One might want to autogenerate those in some languages, but Python has
> >introspection:
>
> >class BaseAB:
> >  def visit( self, vis ):
> >    getattr( vis, 'visit_%s'% self.__class__.__name__ )( self )
>
> >And it's easier to modify the default behavior this way than in
> >autogenerated code too.
>
> This is kind of the wrong way around - this is an example of
> OO jiggery pokery that will be difficult to do by generating the
> source code - are there things that can be done by generating
> the source code that cannot be done with OO?

Yes, I was examining the special case of generating OO code.



More information about the Python-list mailing list