Friday, March 13, 2009

Is there any isString, isList function in Python?

There is a function similar to that. But better than that.

from types import *

#to test it a Object is String
>>>type("string") is StringType
True
>>>type(124) is IntType
True

3 comments:

redfood said...

or just

type("string") is str

type([]) is list

type(123) is int

no import needed

Swordsman said...

The proper way to do this is to use the builtin method isinstance().

>>> isinstance('string', str)
True
>>> isinstance(124, int)
True
>>> isinstance([], list)
True

atlas245 said...

I thought the post made some good points on web scrapers, I use python for simple web scrapers, data extraction can be a time consuming process but for larger projects like the web, files, or documents i tried "web scrapers" which worked great, they build quick custom screen scrapers, web scrapers, and data parsing programs