Metaprogramming Example

andrew cooke andrew at acooke.org
Sat Apr 19 10:34:40 EDT 2008


On Apr 18, 4:48 am, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:
[...]
> Practically, this means that (amongst other niceties) :
> - you can define functions outside classes and use them as instance or
> class methods
> - you can add/replaces methods dynamically on a per-class or
> per-instance basis
> - you can access the function object of a method and use it as a function
> - you can define your own callable types, that - if you implement the
> appropriate support for the descriptor protocol - will be usable as
> methods too

ok, that's convincing (i had thought the majority of these were
already
possible, albeit with some kind of hard-coded "magic" behind the
scenes).

[...]
> > by referring to the titanic
> > i didn't mean that python was a disaster, rather that the "iceberg" is
> > still there (i am not 100% sure what the iceberg is, but it's
> > something
> > to do with making namespaces explicit in some places and not others).
>
> I guess you're thinking of the self argument, declared in the function's
> signature but not "explicitly passed" when calling the method ?

not really.  more to do with when namespaces (i am not sure i have the
right term - the dictionary that provides the mapping from name to
object)
are explicit or implicit.  for example, python has closures (implicit
lookup) and "self" (explicit lookup).

but as i said, i don't have a clear argument - something just feels
"odd".
at the same time, i know that language design is a practical business
and so this is probably not important.

finally, thank you for pointing me to sql alchemy (i think it was
you?).
it really is excellent.

andrew



More information about the Python-list mailing list