How to determine the bool between the strings and ints?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Sep 7 11:51:59 EDT 2007


Jorgen Bodde a écrit :
> Hi All,
> 
> I have a dictionary with settings. The settinfgs can be strings, ints
> or bools. I would like to write this list dynamically to disk in a big
> for loop, unfortunately the bools need to be written as 0 or 1 to the
> config with WriteInt, the integers also with WriteInt and the strings
> with a simple Write.
> 
> The list is something like;
> 
> options[A] = True
> options[B] = 1
> options[C] = "Hello"
> 
> I wanted to use isinstance to determine if it is a bool or an int or a
> string. However I am confused trying it out in the interactive editor;
> 
>>>> a = False
>>>> if isinstance(a, bool):
> ... 	print "OK"
> ... 	
> OK
>>>> if isinstance(a, int):
> ... 	print "OK"
> ... 	
> OK
> 
> I don't get it. is the bool derived from 'int' in some way?

Obviously : yes !-)

> What is
> the best way to check if the config I want to write is an int or a
> bool ?

 >>> isinstance(0, bool)
False
 >>> isinstance(1, bool)
False
 >>>

But anyway, I don't get the point, since "the bools need to be written 
as 0 or 1 to the config with WriteInt, the integers also with WriteInt". 
So you just don't care if it's a bool or not ? Or did I miss something ?



More information about the Python-list mailing list