Function lookup using a directory.

Johann Hibschman johann at physics.berkeley.edu
Tue Jun 19 18:53:04 CEST 2001


andy pevy writes:

> The killer was the actual code to call the looked up class :- 

>     try:
>         h = command_table[command[0]]
>     except:
>         print command[0]+' not found'
    
>     h.run(h(),command)

> It seems that you have to manually pass in the 'self' parameter
> when calling functions this way.

Two points:

1. That last line should be "h().run()" to be idiomatic.  First create
   the instance, then run the "run" method.

2. Why are you using classes at all?  If things are really as simple
   as you make it seem, just use functions.

-- 
Johann Hibschman                           johann at physics.berkeley.edu



More information about the Python-list mailing list