How to determine the bool between the strings and ints?

Zentrader zentraders at gmail.com
Fri Sep 7 15:26:46 EDT 2007


On Sep 7, 11:30 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> On Fri, 07 Sep 2007 18:49:12 +0200, Jorgen Bodde wrote:
> > As for why caring if they are bools or not, I write True and False to
> > the properties, the internal mechanism works like this so I need to
> > make that distinction.
>
> Really?  Can't you just apply the `int()` function?
>
> In [52]: map(int, [1, 0, True, False])
> Out[52]: [1, 0, 1, 0]
>
> Ciao,
>         Marc 'BlackJack' Rintsch

Blackjack's solution would take care of the problem, so this is just
for general info.  Looks like a "feature" of isinstance() is to
consider both True and 1 as booleans, but type() distinguishes between
the two.
>>> x=True
... if type(x) == type(1):
...    print "int"
... else:
...    print "not int"
...
not int

 if type(x) == type(True):
...    print "bool"
...
bool




More information about the Python-list mailing list