Function lookup using a directory.

andy.pevy at nokia.com andy.pevy at nokia.com
Tue Jun 19 05:15:11 EDT 2001


Hi Again

Ype Kingma <ykingma at accessforall.nl> wrote:


> andy.pevy at nokia.com wrote:
>> 
>> Hi Ype
>> 
>> Ype Kingma <ykingma at accessforall.nl> wrote:
>> > Andy,
>> 
>> > In addition to the earlier replies:
>> 
>> > Your run() method seems to be checking for
>> > presence of arguments, so you might
>> > consider defining it with an extra '*' as:
>> 
>> > class Help0:
>> >     def run(self, *which):
>> >         if len(which) == 1:
>> >             print 'Help no args'
>> >         else:
>> >             print 'Help args'
>> 
>> > This will give you a tuple with the passed arguments,
>> > in your case an empty tuple.
>> 
>> The argument passed to thee run method is a list, so does this still necessary ??.

> That depends on what you want to check in the method.

> Your own code (below) calls the method without arguments:

>> >>     h.run()     # Call the run method of the selected class.

> This would cause 'which' to be set to an empty tuple for
> the execution of the method.

My mistake, I should have called the function wih the user entered data
split into a list.

> Calling it as:

>     h.run([])

> would cause 'which' to be set to a tuple containing an empty list.


> In case you want the empty list to be the default value 
> define the method as:

>     def run(self, which=[]):

> This would cause the invocation

> h.run()

> to have 'which' bound to an empty list during execution.

> Good luck,
> Ype

I am now calling f.run(command) 
and I get the following error message :-

TypeError: unbound method must be called with class instance 1st argument


I still have a lot to learn about Python me thinks.. 

-- 

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