Re: where are isinstance types documented?
- From: "Simon Brunning" <simon@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 26 Sep 2006 11:37:37 +0100
On 9/26/06, Simon Brunning <simon@xxxxxxxxxxxxxxxxxx> wrote:
On 26 Sep 2006 02:59:07 -0700, codefire <tony.bedford@xxxxxxxxx> wrote:
> For example isinstance(a, int) works fine but isinstance(s, string)
> doesn't - because 'string is not known'.
In this case, you want "str" rather than "string".
A couple of points to consider:
Firstly, do you really need to use isinstance() at all? It's often not
necessary. Consider a duck-typing approach instead - i.e. to just try
using the object as a string, and to deal with exceptions arising from
the possibility that it isn't. This approach would allow string-like
objects as well as "real" strings.
Secondly, if you *really* want to use isinstance(), "basestring" is
the super-type of both "str" and "unicode", so it's more likely to be
what you want.
--
Cheers,
Simon B,
simon@xxxxxxxxxxxxxxxxxx
.
- References:
- where are isinstance types documented?
- From: codefire
- where are isinstance types documented?
- Prev by Date: Re: Printing a percent sign
- Next by Date: Re: where are isinstance types documented?
- Previous by thread: Re: where are isinstance types documented?
- Next by thread: concat next line with previous
- Index(es):
Relevant Pages
|