[Baypiggies] Newbie-ish type questions...

Kelly Yancey kelly at nttmcl.com
Wed Apr 23 11:01:55 CEST 2008

Charles Merriam wrote:
> Hello,
> I've been creating a growing number of type functions of the form:
> def is_list(l):
>     return type(l) is list
> def is_string(s):
>     return isinstance(s, basestring)
> def is_iter(i):
>     return hasattr(i, "next") and hasattr(i, "__iter__")
> ...etc., etc.
> I feel like I must of missed something when I learned Python.  Is
> there a simple call I'm missing for
> these?  Does this get better in 3.0?

You aren't missing anything. :)
Although, normally I don't bother with type-checking (except when 
writing test cases) and let duck-typing do its thing.

But, yes, it gets better in 3.0:


Kelly Yancey

More information about the Baypiggies mailing list