Specifing arguments type for a function

Maric Michaud maric at aristote.info
Tue Jun 20 07:32:08 EDT 2006


Le Mardi 20 Juin 2006 13:28, Maric Michaud a écrit :
> if not getattr(arg, '__iter__') and not getattr(arg, '__getitem__') :
>     raise ValueError('Function accepts only iterables') # or error handling
> code

oops, hasattr of course :

if not hasattr(arg, '__iter__') and not hasattr(arg, '__getitem__') :
     raise ValueError('Function accepts only iterables') # or error handling

-- 
_____________

Maric Michaud
_____________

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097



More information about the Python-list mailing list