How to return an "not string' error in function?

breakfastea at gmail.com breakfastea at gmail.com
Thu Sep 21 12:02:52 EDT 2006


Or yes that seems a handy way:)

Thanks for all wonderful people here:)

Peace


Duncan Booth wrote:
> Tim Chase <python.list at tim.thechases.com> wrote:
>
> > This will return true for both regular strings and for unicode
> > strings.  If that's a problem, you can use
> >
> > >>> import types
> > >>> isinstance("hello", types.StringType)
> > True
> > >>> isinstance(u"hello", types.StringType)
> > False
> > >>> isinstance("hello", types.UnicodeType)
> > False
> > >>> isinstance(u"hello", types.UnicodeType)
> > True
> >
> > ...or, if you don't want to qualify them with "types." each time,
> > you can use
> >
> > >>> from types import StringType, UnicodeType
> >
> > to bring them into the local namespace.
>
> They already are in the builtin namespace under their more usual names of
> str and unicode respectively, so there is no need to import them, just use
> them:
> 
> >>> isinstance("hello", str)
> True
> 
> ... etc ...




More information about the Python-list mailing list