kyosohma at gmail.com
Tue Mar 3 18:03:22 CET 2009
On Mar 3, 10:57 am, Oltmans <rolf.oltm... at gmail.com> wrote:
> I'm reading from a file that contains text like
> When I read the integer 5 I want to make sure it's an integer.
> Likewise, for strings, I want to make sure if something is indeed a
> string. So how do I check types in Python? I want to check following
> 1- integers
> 2- strings
> 3- testing types of a particular class
> 4- decimal/floats
> Please excuse my ignorance & enlighten me. I will really appreciate
> any help.
I think when you're reading from a file, it will just read each line
as a string. So you'd probably need to either try casting the line
into something else and catch it in an exception handler or use eval.
The normal way to check types is to use the keyword isinstance or just
use the "type" keyword.
More information about the Python-list