how to dispatch objects depending on their class

Curzio Basso curzio.basso at
Wed Aug 11 10:17:09 CEST 2004

Peter Otten wrote:

> func_dict = {A: do_something_with_A, 
>              B: do_something_with_B}
> def func(obj):
>     func_dict[obj.__class__](obj)

ok. it tested and it works. thanks.

now I have only to check if the Visitor Pattern is not more appropriate.

cheers, curzio

More information about the Python-list mailing list