Re: where are isinstance types documented?



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
.



Relevant Pages

  • Re: some c# questions!! please send me the answer
    ... TryParse first to see if the string is a valid DateTime before doing ... In .NET 1.1 all you can do is Prase and catch any exceptions ... Boxing is creating a "reference" shell around a value object so that it ... each "int" and then adds those object wrappers to the ...
    (microsoft.public.dotnet.csharp.general)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • RE: Controling Modal Dialogs (Solution)
    ... doesn't return until the 'modal' browser returns. ... string varOptions) ... public void DocumentComplete ... int rc = winDisp.Invoke(rgDispId, ref guid, 0, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Gcc compatible header file
    ... A string collection is a table of zero terminated strings that will grow ... typedef struct _StringCollection StringCollection; ... int; ... bool; ...
    (comp.lang.c)
  • Kernighan and Pikes "Beautiful" Code
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)