Re: 0 in [True,False] returns True

2005-12-16 Thread Antoon Pardon
Op 2005-12-15, Grant Edwards schreef [EMAIL PROTECTED]: On 2005-12-15, Antoon Pardon [EMAIL PROTECTED] wrote: Well, in my case, a given name (or return value) is always bound to a floating point object. I don't test the type of the object and treat it in two different ways depending on what

Re: 0 in [True,False] returns True

2005-12-16 Thread Grant Edwards
On 2005-12-16, Antoon Pardon [EMAIL PROTECTED] wrote: Your examples are still both very different from the NaN example. A NaN is a floating point operation that supports all the same operations as all other floating point operations. In your example an integer object of -2 does not support

Re: 0 in [True,False] returns True

2005-12-15 Thread Antoon Pardon
Op 2005-12-14, Grant Edwards schreef [EMAIL PROTECTED]: On 2005-12-14, Antoon Pardon [EMAIL PROTECTED] wrote: Well, as you might argue, I'm not tryng to effect a change in your behaviour, I'm simply trying to point out how it could be made more rational. [...] Or return NaN instead of

Re: 0 in [True,False] returns True

2005-12-15 Thread bonono
Antoon Pardon wrote: Op 2005-12-14, Grant Edwards schreef [EMAIL PROTECTED]: On 2005-12-14, Antoon Pardon [EMAIL PROTECTED] wrote: Well, as you might argue, I'm not tryng to effect a change in your behaviour, I'm simply trying to point out how it could be made more rational. [...]

Re: 0 in [True,False] returns True

2005-12-15 Thread Antoon Pardon
Op 2005-12-14, Mike Meyer schreef [EMAIL PROTECTED]: [EMAIL PROTECTED] writes: Steve Holden wrote: It would be somewhat more self-documenting, but why not just use one name to indicate the state and another, only meaningful in certain states, to indicate the callback? Why should I do that?

Re: 0 in [True,False] returns True

2005-12-15 Thread Grant Edwards
On 2005-12-15, Antoon Pardon [EMAIL PROTECTED] wrote: Or return NaN instead of raising exception for numeric functions ? Because usually (in my applications anyway) NaN is a perfectly valid value and not an exception case that needs to be handled. I don't see the difference. In my

Re: 0 in [True,False] returns True

2005-12-14 Thread Antoon Pardon
Op 2005-12-13, Steve Holden schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Op 2005-12-13, Chris Mellon schreef [EMAIL PROTECTED]: [...] If you have a consistent API and you're checking for error values from your GTK functions, then you already have a lot more code than using 2 varaibles will

Re: 0 in [True,False] returns True

2005-12-14 Thread Steve Holden
Antoon Pardon wrote: Op 2005-12-13, Steve Holden schreef [EMAIL PROTECTED]: [...] But lets make an effort to make the code more readable. What about the following suggestion. I use a kind of EnumType with two values: NotRegistered and Registerd. And the name of the type is NotConnected. So I can

Re: 0 in [True,False] returns True

2005-12-14 Thread bonono
Steve Holden wrote: It would be somewhat more self-documenting, but why not just use one name to indicate the state and another, only meaningful in certain states, to indicate the callback? Why should I do that? Checking the type of a variable is conceptually no different form testing

Re: 0 in [True,False] returns True

2005-12-14 Thread Antoon Pardon
Op 2005-12-14, Steve Holden schreef [EMAIL PROTECTED]: Antoon Pardon wrote: It would be somewhat more self-documenting, but why not just use one name to indicate the state and another, only meaningful in certain states, to indicate the callback? Why should I do that? Checking the type of

Re: 0 in [True,False] returns True

2005-12-14 Thread Grant Edwards
On 2005-12-14, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Well, as you might argue, I'm not tryng to effect a change in your behaviour, I'm simply trying to point out how it could be made more rational. What would be the difference in his usage and allowing Null in a RDBMS column? Don't

Re: 0 in [True,False] returns True

2005-12-14 Thread Antoon Pardon
Op 2005-12-14, Grant Edwards schreef [EMAIL PROTECTED]: On 2005-12-14, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Well, as you might argue, I'm not tryng to effect a change in your behaviour, I'm simply trying to point out how it could be made more rational. What would be the difference in

Re: 0 in [True,False] returns True

2005-12-14 Thread Mike Meyer
[EMAIL PROTECTED] writes: Steve Holden wrote: It would be somewhat more self-documenting, but why not just use one name to indicate the state and another, only meaningful in certain states, to indicate the callback? Why should I do that? Checking the type of a variable is conceptually no

Re: 0 in [True,False] returns True

2005-12-14 Thread bonono
Mike Meyer wrote: [EMAIL PROTECTED] writes: Steve Holden wrote: It would be somewhat more self-documenting, but why not just use one name to indicate the state and another, only meaningful in certain states, to indicate the callback? Why should I do that? Checking the type of a

Re: 0 in [True,False] returns True

2005-12-13 Thread Antoon Pardon
test for the obvious if type(v) is bool, but I still find it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity with one of the values in list ? equality

Re: 0 in [True,False] returns True

2005-12-13 Thread bonono
returned True So I changed my test for the obvious if type(v) is bool, but I still find it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity

Re: 0 in [True,False] returns True

2005-12-13 Thread Steve Holden
, but I still find it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity with one of the values in list ? equality, it seems) ; did I miss something

Re: 0 in [True,False] returns True

2005-12-13 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes: The really interesting question your post raises, though, is Why do you feel it's necessary to test to see whether a variable is a Boolean?. What's the point of having Booleans, if you can't tell them from integers? --

Re: 0 in [True,False] returns True

2005-12-13 Thread Antoon Pardon
changed my test for the obvious if type(v) is bool, but I still find it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity with one of the values

Re: 0 in [True,False] returns True

2005-12-13 Thread Erik Max Francis
Paul Rubin wrote: Steve Holden [EMAIL PROTECTED] writes: The really interesting question your post raises, though, is Why do you feel it's necessary to test to see whether a variable is a Boolean?. What's the point of having Booleans, if you can't tell them from integers? Because

Re: 0 in [True,False] returns True

2005-12-13 Thread Steve Holden
Paul Rubin wrote: Steve Holden [EMAIL PROTECTED] writes: The really interesting question your post raises, though, is Why do you feel it's necessary to test to see whether a variable is a Boolean?. What's the point of having Booleans, if you can't tell them from integers? Booleans are

Re: 0 in [True,False] returns True

2005-12-13 Thread Fredrik Lundh
Erik Max Francis wrote: What's the point of having Booleans, if you can't tell them from integers? Because return True is clearer than return 1 if the purpose of the return value is to indicate a Boolean rather than an arbitrary integer. the real reason booleans were added was that

Re: 0 in [True,False] returns True

2005-12-13 Thread Robin Becker
Carsten Haese wrote: ... Where/how did you search? http://docs.python.org/lib/typesseq.html states unambiguously that x in s returns True if an item of s is equal to x, else False . exactly and I see 0==False True so I guess nothing is wrong :) -- Robin Becker --

Re: 0 in [True,False] returns True

2005-12-13 Thread bonono
Erik Max Francis wrote: Paul Rubin wrote: Steve Holden [EMAIL PROTECTED] writes: The really interesting question your post raises, though, is Why do you feel it's necessary to test to see whether a variable is a Boolean?. What's the point of having Booleans, if you can't tell them

Re: 0 in [True,False] returns True

2005-12-13 Thread Steve Holden
returned True So I changed my test for the obvious if type(v) is bool, but I still find it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity with one

Re: 0 in [True,False] returns True

2005-12-13 Thread Erik Max Francis
[EMAIL PROTECTED] wrote: True, but if that is the only reason, Two built-in value of True/False(0/1) serves the need which is what is now(well sort of). Why have seperate types and distinguish them ? Because of this: x = True y = 1 # but I mean it to represent true

Re: 0 in [True,False] returns True

2005-12-13 Thread bonono
Erik Max Francis wrote: [EMAIL PROTECTED] wrote: True, but if that is the only reason, Two built-in value of True/False(0/1) serves the need which is what is now(well sort of). Why have seperate types and distinguish them ? Because of this: x = True y = 1 # but I mean it

Re: 0 in [True,False] returns True

2005-12-13 Thread Erik Max Francis
[EMAIL PROTECTED] wrote: True too, and could be the reason(or similar too) why the OP wants to test the type rather than the logical value of it. The type is for the self-documentation purposes. The value is the same; so no, that's not a good reason either. -- Erik Max Francis [EMAIL

Re: 0 in [True,False] returns True

2005-12-13 Thread Duncan Booth
wrote: if the purpose of the return value is to indicate a Boolean rather than an arbitrary integer. True, but if that is the only reason, Two built-in value of True/False(0/1) serves the need which is what is now(well sort of). Why have seperate types and distinguish them ? True == 1

Re: 0 in [True,False] returns True

2005-12-13 Thread quentel . pierre
Ok, I'll explain why I wanted to test if the value was a boolean I have a program that generates HTML tags with attributes. The principle is that TAG('text',arg1=val1,arg2=val2) generates TAG arg1=val1 arg2=val2text/TAG For HTML attributes that don't have an explicit value (such as the SELECTED

Re: 0 in [True,False] returns True

2005-12-13 Thread bonono
Erik Max Francis wrote: [EMAIL PROTECTED] wrote: True too, and could be the reason(or similar too) why the OP wants to test the type rather than the logical value of it. The type is for the self-documentation purposes. The value is the same; so no, that's not a good reason either. I

Re: 0 in [True,False] returns True

2005-12-13 Thread quentel . pierre
Thanks for the link Carsten, the explanation is clear I didn't know where to search in the Python documentation, there isn't a section about keywords (always wondered why without daring to say - now it's done). So I typed ' in operator Python ' in Google, which gave : - on the first page a link

RE: 0 in [True,False] returns True

2005-12-13 Thread Ron Griswold
I haven't read all of the responses to this thread, so perhaps this has already been suggested. But it occurs to me that if one needs to determine whether a variable is a bool or int it could be done like so: Booltype = False var = 0 Booltype == var True Booltype.__class__ == var.__class__

Re: 0 in [True,False] returns True

2005-12-13 Thread Fredrik Lundh
Duncan Booth wrote: Another reason to have a boolean type is of course to provide a cast: def isNameSet(self): return boolean(self.name) instead of: def isNameSet(self): if self.name: return True else: return False given that Python

Re: 0 in [True,False] returns True

2005-12-13 Thread Duncan Booth
wrote: For HTML attributes that don't have an explicit value (such as the SELECTED attribute in OPTION) the keyword argument to the function must have the value True A better way to do this (given that HTML defines exactly which attributes do not take a value) is to use the attribute name

Re: 0 in [True,False] returns True

2005-12-13 Thread bonono
Fredrik Lundh wrote: Duncan Booth wrote: Another reason to have a boolean type is of course to provide a cast: def isNameSet(self): return boolean(self.name) instead of: def isNameSet(self): if self.name: return True else:

Re: 0 in [True,False] returns True

2005-12-13 Thread Fredrik Lundh
Duncan Booth wrote: For HTML attributes that don't have an explicit value (such as the SELECTED attribute in OPTION) the keyword argument to the function must have the value True A better way to do this (given that HTML defines exactly which attributes do not take a value) is to use the

Re: 0 in [True,False] returns True

2005-12-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: I see you skip another use case of XMLRPC Duncan mentioned, is that a valid reason ? the PEP has the answer. also see my reply to Erik Max Francis: http://groups.google.com/group/comp.lang.python/msg/adb5e9389ea20b3c (the silly Boolean class in that post is taken

Re: 0 in [True,False] returns True

2005-12-13 Thread Stefan Rank
on 13.12.2005 11:39 Fredrik Lundh said the following: Duncan Booth wrote: Another reason to have a boolean type is of course to provide a cast: def isNameSet(self): return boolean(self.name) [snip] given that Python already had a function for this, that wasn't much of a reason:

Re: 0 in [True,False] returns True

2005-12-13 Thread Fredrik Lundh
Duncan Booth wrote: A better way to do this (given that HTML defines exactly which attributes do not take a value) is to use the attribute name and simply generate the attribute only if the value is non-false. another approach (which may or may not be suitable in this case) is to use the

Re: 0 in [True,False] returns True

2005-12-13 Thread Antoon Pardon
cases and I eventually found that for v = 0 the test returned True So I changed my test for the obvious if type(v) is bool, but I still find it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition

Re: 0 in [True,False] returns True

2005-12-13 Thread Chris Mellon
was a boolean, with this test : if v in [True,False] My script didn't work in some cases and I eventually found that for v = 0 the test returned True So I changed my test for the obvious if type(v) is bool, but I still find it confusing that 0 in [True,False] returns True By the way, I searched

Re: 0 in [True,False] returns True

2005-12-13 Thread bonono
Chris Mellon wrote: Granted, of course, it's your code. But I wouldn't accept it in anything I was in charge of. That says it all. It is his code, whether you would accept it means nothing. If you can point out that it is functionally wrong, it may mean something. Otherise, it is nothing more

Re: 0 in [True,False] returns True

2005-12-13 Thread Antoon Pardon
Op 2005-12-13, Chris Mellon schreef [EMAIL PROTECTED]: However I must say the coupling in that interface has a very definite code smell. Why not use two variables, a Boolean registered and an integer ID that is meaningless when registered is False? Because the integer ID can be meaningless

Re: 0 in [True,False] returns True

2005-12-13 Thread Grant Edwards
On 2005-12-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: but seriously, unless you're writing an introspection tool, testing for bool is pretty silly. just use if v or if not v, and leave the rest to Python. The OP's code(and

Re: 0 in [True,False] returns True

2005-12-13 Thread Grant Edwards
On 2005-12-13, Paul Rubin wrote: Steve Holden [EMAIL PROTECTED] writes: The really interesting question your post raises, though, is Why do you feel it's necessary to test to see whether a variable is a Boolean?. What's the point of having Booleans, if you can't tell them from integers?

Re: 0 in [True,False] returns True

2005-12-13 Thread bonono
Grant Edwards wrote: He seems to be testing boolean type, not whether it is true or false. Right. But that's almost always pointless. Knowing whether a variable is a boolean or not is very rarely useful. What one wants to know is whether a varible is true or not. The code for that is:

Re: 0 in [True,False] returns True

2005-12-13 Thread Mike Meyer
Fredrik Lundh [EMAIL PROTECTED] writes: Duncan Booth wrote: For HTML attributes that don't have an explicit value (such as the SELECTED attribute in OPTION) the keyword argument to the function must have the value True A better way to do this (given that HTML defines exactly which

Re: 0 in [True,False] returns True

2005-12-13 Thread Fredrik Lundh
Mike Meyer wrote: (for example, in img ismap, ismap is the value, not the attribute name. it's up to the parser to figure out (from the DTD) that this value can only be used by the ismap attribute, and interpret it as img ismap=ismap) But this isn't necessarilly true: img alt=ismap is

Re: 0 in [True,False] returns True

2005-12-13 Thread Steve Holden
Antoon Pardon wrote: Op 2005-12-13, Chris Mellon schreef [EMAIL PROTECTED]: [...] If you have a consistent API and you're checking for error values from your GTK functions, then you already have a lot more code than using 2 varaibles will cost you. 10 lines, maybe. The fact that you think

Re: 0 in [True,False] returns True

2005-12-13 Thread Xavier Morel
Mike Meyer wrote: But this isn't necessarilly true: img alt=ismap is perfectly legal. mike Legal but irrelevant since the ALT attribute cannot be minimized. -- http://mail.python.org/mailman/listinfo/python-list

Re: 0 in [True,False] returns True

2005-12-13 Thread Steven D'Aprano
On Tue, 13 Dec 2005 09:46:30 +, Steve Holden wrote: Paul Rubin wrote: Steve Holden [EMAIL PROTECTED] writes: The really interesting question your post raises, though, is Why do you feel it's necessary to test to see whether a variable is a Boolean?. What's the point of having

0 in [True,False] returns True

2005-12-12 Thread Pierre Quentel
that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity with one of the values in list ? equality, it seems) ; did I miss something ? Regards, Pierre -- http

Re: 0 in [True,False] returns True

2005-12-12 Thread Fredrik Lundh
it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity with one of the values in list ? equality, it seems) ; did I miss something ? issubclass(bool, int

Re: 0 in [True,False] returns True

2005-12-12 Thread Carsten Haese
for the obvious if type(v) is bool, but I still find it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity with one of the values in list ? equality, it seems

Re: 0 in [True,False] returns True

2005-12-12 Thread Steven Bethard
Pierre Quentel wrote: In some program I was testing if a variable was a boolean, with this test : if v in [True,False] My script didn't work in some cases and I eventually found that for v = 0 the test returned True This seems like a strange test. What is this code trying to do? If

Re: 0 in [True,False] returns True

2005-12-12 Thread David Wahler
still find it confusing that 0 in [True,False] returns True From the docs: Python Library Reference, section 2.3.10.9: Boolean values are the two constant objects False and True. They are used to represent truth values (although other values can also be considered false or true). In numeric contexts

Re: 0 in [True,False] returns True

2005-12-12 Thread bonono
(v) is bool, but I still find it confusing that 0 in [True,False] returns True By the way, I searched in the documentation what obj in list meant and couldn't find a precise definition (does it test for equality or identity with one of the values in list ? equality, it seems) ; did I

Re: 0 in [True,False] returns True

2005-12-12 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: but seriously, unless you're writing an introspection tool, testing for bool is pretty silly. just use if v or if not v, and leave the rest to Python. The OP's code(and his work around) doesn't look like he is testing for boolean which of course explains why

Re: 0 in [True,False] returns True

2005-12-12 Thread bonono
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: but seriously, unless you're writing an introspection tool, testing for bool is pretty silly. just use if v or if not v, and leave the rest to Python. The OP's code(and his work around) doesn't look like he is testing for