Member function names

Gordon McMillan gmcm at hypernet.com
Fri Apr 7 20:05:44 CEST 2000


Andrew Stribblehill wrote:

> For some things, such as XML parsers, based on xmllib, I have to do
> stuff like this:
> 
> class foo(XMLParser):
>     start_h1:
>         print "start_h1",
>     end_h1:
>         print "end_h1",
> 
> (etc)
> 
> Is there any way I can do something like this?
> 
> class foo(XMLParser):
>     generic:
>         print __member_function_name__,
>     start_h1=generic
>     end_h1=generic
> 

When everything about your example code is broken, it's 
difficult to know what broke on your real attempts. In general, 
this technique works fine.

>>> class A:
...  def a(self):
...   print "hi"
...  b = a
...
>>> a = A()
>>> a.b()
hi
>>>

- Gordon




More information about the Python-list mailing list