From: John H. <jd...@gm...> - 2008-07-21 13:43:02
|
On Mon, Jul 21, 2008 at 7:51 AM, David Kaplan <Dav...@ir...> wrote: > 2) Can someone explain to me why is_string_like in the cbook doesn't > just do isinstance(obj,str)? Is there anything "string like" that won't > be caught be this isinstance call? In [65]: s = u'jdh' In [66]: isinstance(s, str) Out[66]: False In [67]: isinstance(s, unicode) Out[67]: True So we could check for str or unicode, but a user may be using a custom string like class from some c++ extension code that is part of a large in house API. The point is that we don't care if it *is* a string, we just want it to act like a string http://en.wikipedia.org/wiki/Duck_typing |