Iterate through a list calling functions

Kent Johnson kent37 at tds.net
Sun Jun 5 22:08:43 EDT 2005


David Pratt wrote:
> Hi Kent.  Thank you for your reply.  I gave this a go but get the 
> following traceback:
> ...
>     result = validator(name, value)
> TypeError: 'str' object is not callable
> 
> Have put validators in list and iterate over it as in following:
> 
>     validator_list = 
> [isContainedIn,isDate,isDecimal,isEmail,isEmpty,isInteger...
>          more validators....]   
>     results={}
>     for validator in validators_list:
>         result = validator(name, value)
>         if type (result) in StringTypes:
>             # do some stuff...
>     return results

Are you sure you don't have quoted strings in your validator list? That is what the error message indicates. Can you post a small complete example of the code that fails?

or put
print repr(validator)

before the line that calls validator so you can see exactly what you are trying to call.

Kent



More information about the Python-list mailing list