Type constants?
Remco Gerlich
scarblac at pino.selwerd.nl
Tue May 1 10:59:59 EDT 2001
Roy Smith <roy at panix.com> wrote in comp.lang.python:
> Is there a way of writing type('') as a constant? What I want to do
> is check to see if an object is a string. The best I can think of is
> to do something like:
>
> if type(foo) == type('')
>
> which would work, but seems kind of silly. Is there no pre-defined
> object somewhere whose value is <type 'string'>?
You're looking for types.StringType.
import types
if type(foo) is types.StringType:
But comparing to type('') is pretty common too.
--
Remco Gerlich
More information about the Python-list
mailing list