Function lookup using a directory.

andy.pevy at nokia.com andy.pevy at nokia.com
Wed Jun 20 09:06:37 EDT 2001


Hi Johann

Johann Hibschman <johann at physics.berkeley.edu> wrote:
> 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.

Well, it is as much a learning excercise as anything, and as such I will
have functions in the main programme and classes in the extensions.

> -- 
> Johann Hibschman                           johann at physics.berkeley.edu

-- 

We were always told that a million monkeys typing for a million years
would eventually produce the works of Shakespeare. Now, thanks to the
Internet, we know this is not true.



More information about the Python-list mailing list