Testing validity of for...in...

Richard Philips richard.philips at ua.ac.be
Mon Nov 3 12:53:18 CET 2003


 From the "The Pragmatic Programmer / Dave Thomas, Andy Hunt",
I acquired the habit to insert assertions in function declarations:

def maxlength(mylist):
    assert isinstance(mylist, list), "A list with strings"
    max = -1
    for item in list:
        if len(item)>max:
           max = len(item)
    return max

But if you look at the code, maxlength is meaningful if mylist supports 
the "for ... in ...".

Is there an easy way to test if "mylist" supports  "for ... in ..." ?

Thank you,


Dr. Richard PHILIPS
University of Antwerp
Systemmanager Anet

Phone: +32 3 820.21.53
Fax:   +32 3 820.21.59
GSM:   0478/36.76.28
Email: Richard.Philips at ua.ac.be

More information about the Python-list mailing list