Musings about Python syntax
Jim Althoff
jima at aspectdv.com
Mon Oct 25 15:45:47 EDT 1999
Where can one find out more info on
"hasinterface" and "as_sequence"?
Is this a standard idiom for testing
for "sequence-ness"?
Is this different/better than something
like
hasattr(anObject,"__get_item__")
I often want to determine whether or not
I am dealing with a sequence and would
like to use a "best practices" mechanism.
type(anObject) == type([]) or
type(anObject) == type(())
seems too limited, BTW.
Any advice?
Thanks,
Jim
>
> def len(obj):
> if hasinterface(obj, as_sequence):
> return obj.sequence_length()
> if hasinterface(obj, as_mapping):
> return obj.mapping_length()
> raise TypeError, "len() of unsized object"
>
>which, for my non-purist eyes, surely looks as if
>Python treats "obj" as an arbitrary object.
>
></F>
>
><!-- (the eff-bot guide to) the standard python library:
>http://www.pythonware.com/people/fredrik/librarybook.htm
>-->
>
>
>--
>http://www.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list