Re: How to determine the bool between the strings and ints?

2007-09-08 Thread Ricardo Aráoz
Steven D'Aprano wrote: ... .. . > You know, one or two examples was probably plenty. The other six or seven > didn't add anything to your post except length. > > Also, type testing by equality is generally not a good idea. For example: > > class HexInt(int): > """Like built-in ints, but prin

Re: How to determine the bool between the strings and ints?

2007-09-08 Thread Steven D'Aprano
On Sat, 08 Sep 2007 12:08:16 -0300, Ricardo Aráoz wrote: >> if type(x) == type(True): >> ...print "bool" >> ... >> bool >> >> > Or just : > a = True type(a) == int > False [snip] You know, one or two examples was probably plenty. The other six or seven didn't add anything to

Re: How to determine the bool between the strings and ints?

2007-09-08 Thread Ricardo Aráoz
Zentrader wrote: > On Sep 7, 11:30 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> 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 >>>

Re: How to determine the bool between the strings and ints?

2007-09-07 Thread Steven D'Aprano
On Fri, 07 Sep 2007 17:40:44 +0200, Jorgen Bodde wrote: > is the bool derived from 'int' in some way? Yes. >>> issubclass(bool, int) True > What is the best way to > check if the config I want to write is an int or a bool ? if isinstance(value, bool): print "it's a bool, or a subclass of

Re: How to determine the bool between the strings and ints?

2007-09-07 Thread Marc 'BlackJack' Rintsch
On Fri, 07 Sep 2007 12:26:46 -0700, Zentrader wrote: > Looks like a "feature" of isinstance() is to consider both True and 1 as > booleans, but type() distinguishes between the two. That's not a "feature", it is just OOP. `bool` is a subclass of `int` therefore every `bool` instance is also an i

Re: How to determine the bool between the strings and ints?

2007-09-07 Thread Zentrader
On Sep 7, 11:30 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> 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 distincti

Re: How to determine the bool between the strings and ints?

2007-09-07 Thread Marc 'BlackJack' Rintsch
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,

Re: How to determine the bool between the strings and ints?

2007-09-07 Thread Jorgen Bodde
Awesome! Thanks you! 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. Thanks again guys, - Jorgen ps. Sorry TheFlyingDutch for mailing you personally, I keep forgetting this mailinglis

Re: How to determine the bool between the strings and ints?

2007-09-07 Thread TheFlyingDutchman
On Sep 7, 8:40 am, "Jorgen Bodde" <[EMAIL PROTECTED]> wrote: > 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

Re: How to determine the bool between the strings and ints?

2007-09-07 Thread Bruno Desthuilliers
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

How to determine the bool between the strings and ints?

2007-09-07 Thread Jorgen Bodde
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 si