Re: Implicit conversion to boolean in if and while statements

2013-02-15 Thread Serhiy Storchaka
On 10.02.13 13:37, Steven D'Aprano wrote: Unfortunately, Python has a minor design flaw. One of the most common use-cases for sets is for membership testing of literal sets: def example(arg): if arg in {'spam', 'ham', 'eggs', 'cheese'}: ... Unfortunately, set literals

Re: Implicit conversion to boolean in if and while statements

2013-02-15 Thread Ian Kelly
On Tue, Feb 12, 2013 at 10:48 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Monday, February 11, 2013 11:55:19 PM UTC-6, Chris Angelico wrote: On Tue, Feb 12, 2013 at 12:06 PM, 8 Dihedral wrote: A permanently mutated list is a tuple of constant objects. I nominate this line as

Re: Implicit conversion to boolean in if and while statements

2013-02-15 Thread Chris Angelico
On Sat, Feb 16, 2013 at 7:12 AM, Ian Kelly ian.g.ke...@gmail.com wrote: FYI, the general consensus here is that he (8 Dihedral) is a bot. It posts in non sequiturs and fails to respond meaningfully to direct queries. A few months ago I posed an obvious Turing test for it, which it

Re: Implicit conversion to boolean in if and while statements

2013-02-12 Thread Rick Johnson
On Monday, February 11, 2013 11:55:19 PM UTC-6, Chris Angelico wrote: On Tue, Feb 12, 2013 at 12:06 PM, 8 Dihedral wrote: A permanently mutated list is a tuple of constant objects. I nominate this line as bemusing head-scratcher of the week. Actually the statement is fact IF you can grok

Re: Implicit conversion to boolean in if and while statements

2013-02-12 Thread Chris Angelico
On Wed, Feb 13, 2013 at 4:48 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: Your confusion may stem from interpreting constant as the CS term CONSTANT[1]; whereby the objects in the tuple are programming CONSTANTS, that is, unable to change. Uhh, yeah. Not being Humpty Dumpty, I

Re: Implicit conversion to boolean in if and while statements

2013-02-12 Thread 88888 Dihedral
Rick Johnson於 2013年2月13日星期三UTC+8上午1時48分07秒寫道: On Monday, February 11, 2013 11:55:19 PM UTC-6, Chris Angelico wrote: On Tue, Feb 12, 2013 at 12:06 PM, 8 Dihedral wrote: A permanently mutated list is a tuple of constant objects. I nominate this line as bemusing head-scratcher

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Sunday, February 10, 2013 5:37:46 AM UTC-6, Steven D'Aprano wrote: Rick Johnson wrote: IMO Set Types should only exists as a concequence of freezing an array, Sets are not frozen lists. Indeed. That wording was a bit clumsy on my part. and should have NO literal syntax available.

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Saturday, February 9, 2013 11:04:42 PM UTC-6, Chris Angelico wrote: On Sun, Feb 10, 2013 at 3:54 PM, Rick Johnson wrote: Well Chris i have wonderful news for you! Python /does/ have homogenous arrays, and they're called, wait for it. arrays! That's not a built-in. But you were

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Mon, Feb 11, 2013 at 11:18 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Sunday, February 10, 2013 5:37:46 AM UTC-6, Steven D'Aprano wrote: Rick Johnson wrote: IMO Set Types should only exists as a concequence of freezing an array, Sets are not frozen lists. Indeed. That

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Mon, Feb 11, 2013 at 11:28 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Saturday, February 9, 2013 11:04:42 PM UTC-6, Chris Angelico wrote: On Sun, Feb 10, 2013 at 3:54 PM, Rick Johnson wrote: Well Chris i have wonderful news for you! Python /does/ have homogenous arrays, and

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 6:40:23 AM UTC-6, Chris Angelico wrote: [...] Or doing what you were pointing and laughing at Pike for, and using two-symbol delimiters. You could even make it majorly logical: list_ = [[ 1, 2, 3 ]] tuple_ = ([ 1, 2, 3 ]) dict_ = [{ 1, 2, 3 }] frozendict_ = ({

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 6:50:03 AM UTC-6, Chris Angelico wrote: On Mon, Feb 11, 2013 at 11:28 PM, Rick Johnson Well i would expect anyone who considers himself a python programmer (not to mention pythonista!) to at minimum be familiar with the stdlib. [...] [...] If there is

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:13 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: I am vehemently against using more than one opening seq char and one closing seq char. ... we could use start and end tags like: set{1,2,3}set where set{ and }set are delimiters. Interesting. So what

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:28 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: I am sure there are quite a few Chris. But if you expect to around making statements like: Python does not have typed arrays, then don't get all upset when someone corrects you. Oh, I don't mind being

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread 88888 Dihedral
Rick Johnson於 2013年2月11日星期一UTC+8下午9時13分58秒寫道: On Monday, February 11, 2013 6:40:23 AM UTC-6, Chris Angelico wrote: [...] Or doing what you were pointing and laughing at Pike for, and using two-symbol delimiters. You could even make it majorly logical: list_ = [[ 1, 2, 3 ]]

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 7:35:23 AM UTC-6, Chris Angelico wrote: On Tue, Feb 12, 2013 at 12:13 AM, Rick Johnson wrote: I am vehemently against using more than one opening seq char and one closing seq char. ... we could use start and end tags like: set{1,2,3}set where set{ and

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Rick Johnson
On Monday, February 11, 2013 7:52:24 AM UTC-6, Chris Angelico wrote: [...] But my statement wasn't based on my own knowledge of the stdlib, but rather on this: On Sat, Feb 9, 2013 at 6:58 AM, Rick Johnson wrote: I'm a bit unnerved by the sum function. Summing a sequence only makes sense

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Mark Janssen
On Fri, Feb 8, 2013 at 9:48 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Friday, February 8, 2013 9:16:42 AM UTC-6, Steven D'Aprano wrote: Rick Johnson wrote: Just because /everything/ in Python is an object does not mean that Python is 100% OOP. The whole idea of make everything

Re: Implicit conversion to boolean in if and while statements

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:06 PM, 8 Dihedral dihedral88...@googlemail.com wrote: A permanently mutated list is a tuple of constant objects. I nominate this line as bemusing head-scratcher of the week. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2013-02-10 Thread Steven D'Aprano
Rick Johnson wrote: IMO Set Types should only exists as a concequence of freezing an array, Sets are not frozen lists. and should have NO literal syntax avaiable. Unfortunately, Python has a minor design flaw. One of the most common use-cases for sets is for membership testing of literal

Re: Implicit conversion to boolean in if and while statements

2013-02-10 Thread Roy Smith
In article 5117868b$0$29998$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Sets are not frozen lists. Right. Tuples are frozen lists (ducking and running). -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2013-02-10 Thread Thomas Rachel
Am 10.02.2013 12:37 schrieb Steven D'Aprano: So, in Python 4000, my vote is for set literals { } to create frozensets, and if you want a mutable set, you have to use the set() type directly. 4000 sounds about long future. In the meanwhile, a new syntax element could be introduced fpr

Re: Implicit conversion to boolean in if and while statements

2013-02-10 Thread Rick Johnson
On Saturday, February 9, 2013 10:50:25 PM UTC-6, Chris Angelico wrote: [...] I don't understand. Wouldn't freezing an array (list) result in a tuple? And, why should there be no literal syntax for them? Having a convenient literal notation for every basic type is extremely handy. Actually

Re: Implicit conversion to boolean in if and while statements

2013-02-10 Thread alex23
On Feb 8, 4:29 pm, Rick Johnson rantingrickjohn...@gmail.com wrote: That's a strange thing to say when you go on to provide an example that tests the validity of the object each and every time: Here's a tip: context is important. I was referring to not having to *explicitly* test if a label

Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Rick Johnson
On Friday, February 8, 2013 11:01:00 PM UTC-6, Chris Angelico wrote: [...] Another advantage of using two characters: There's no conflict between set and dict literals. How do you notate an empty set in Python? {} means an empty dict. What makes you believe that a language must provide

Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Chris Angelico
On Sun, Feb 10, 2013 at 3:26 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Friday, February 8, 2013 11:01:00 PM UTC-6, Chris Angelico wrote: [...] Another advantage of using two characters: There's no conflict between set and dict literals. How do you notate an empty set in Python?

Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Rick Johnson
On Friday, February 8, 2013 7:17:26 PM UTC-6, Chris Angelico wrote: On Sat, Feb 9, 2013 at 11:49 AM, Rick Johnson nested_list = array(array(string)) Actually, that's not a declaration, that's an assignment; and in Pike, a 'type' is a thing, same as it is in Python (though not quite). If I

Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Chris Angelico
On Sun, Feb 10, 2013 at 3:54 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: Well Chris i have wonderful news for you! Python /does/ have homogenous arrays, and they're called, wait for it. arrays! Imagine that! That's not a built-in. But you were the one who complained about the

Re: Implicit conversion to boolean in if and while statements

2013-02-09 Thread Rick Johnson
On Friday, February 8, 2013 7:06:34 PM UTC-6, Ian wrote: On Fri, Feb 8, 2013 at 12:58 PM, Rick Johnson wrote: I'm a bit unnerved by the sum function. Summing a sequence only makes sense if the sequence in question contains /only/ numeric types. For that reason i decided to create a

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Mark Lawrence
On 08/02/2013 06:15, Chris Angelico wrote: On Fri, Feb 8, 2013 at 4:53 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: And which Univeristy would you recommend for studying the intricacies of gobbledygook? ;-) Dunno, where'd you get your degree in logic? From the University of

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Thomas Rachel
Am 08.02.2013 07:29 schrieb Rick Johnson: Consider this: if connect(my:db) as db: do something No need to make a call and then test for the validity of the call when you can do both simultaneously AND intuitively. Would be great, but can be emulated with def ifiter(x):

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Steven D'Aprano
Rick Johnson wrote: On Monday, July 16, 2012 7:43:47 PM UTC-5, Steven D'Aprano wrote: Really Rick? Digging out a post from nearly seven months ago? You must really be bored silly. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Steven D'Aprano
Rick Johnson wrote: GvR has always been reluctant to incorporate full OOP machinery for some reason. Python is a fully object oriented language. It is *more* object oriented than, say, Java. - everything in Python is an object, there is no distinction between boxed and unboxed variables; -

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread MRAB
On 2013-02-08 07:22, Steven D'Aprano wrote: Rick Johnson wrote: Why even have a damn bool function if you're never going to use it? bool is for converting arbitrary objects into a canonical True or False flag. E.g. one use-case is if you wish to record in permanent storage a flag, and don't

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Rick Johnson
On Friday, February 8, 2013 9:16:42 AM UTC-6, Steven D'Aprano wrote: Rick Johnson wrote: GvR has always been reluctant to incorporate full OOP machinery for some reason. Python is a fully object oriented language. It is *more* object oriented than, say, Java. Oh really? *chuckles* -

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Roy Smith
In article ee71b775-b527-4bb3-a080-12aad962b...@googlegroups.com, Rick Johnson rantingrickjohn...@gmail.com wrote: The best way to describe Python is as promiscuous language who secretly longs to be 100% OOP, and to fulfill this fantasy it cross-dresses in OOP lingerie on the weekends.

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Rick Johnson
On Friday, February 8, 2013 11:48:43 AM UTC-6, Rick Johnson wrote: [...] So using a /real/ OOP paridigm we would do the following: ## START TRUE OOP PARIDIGM ## [...snip naive example...] Actually my example API is littered with artifacts of a python global function architecture. In

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Steven D'Aprano
MRAB wrote: On 2013-02-08 07:22, Steven D'Aprano wrote: Prior to Python 3, the special method __bool__ was spelled __nonempty__, which demonstrates Python's philosophy towards duck-typing bools. Incorrect, it was spelled __nonzero__. Oops, so it was. Sorry for the brain-fart. __nonzero__

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Chris Angelico
On Sat, Feb 9, 2013 at 6:58 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: I'm a bit unnerved by the sum function. Summing a sequence only makes sense if the sequence in question contains /only/ numeric types. For that reason i decided to create a special type for holding Numerics. This

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Rick Johnson
On Friday, February 8, 2013 6:05:54 PM UTC-6, Chris Angelico wrote: The sum builtin works happily on any sequence of objects that can be added together. It works as an excellent flatten() method: nested_list = [[q], [w,e], [r,t,u], [i,o,p]] sum(nested_list,[]) ['q', 'w', 'e', 'r', 't',

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Ian Kelly
On Fri, Feb 8, 2013 at 12:58 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: I'm a bit unnerved by the sum function. Summing a sequence only makes sense if the sequence in question contains /only/ numeric types. For that reason i decided to create a special type for holding Numerics.

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Chris Angelico
On Sat, Feb 9, 2013 at 11:49 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Friday, February 8, 2013 6:05:54 PM UTC-6, Chris Angelico wrote: The sum builtin works happily on any sequence of objects that can be added together. It works as an excellent flatten() method: nested_list =

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Ian Kelly
On Fri, Feb 8, 2013 at 5:49 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Friday, February 8, 2013 6:05:54 PM UTC-6, Chris Angelico wrote: The sum builtin works happily on any sequence of objects that can be added together. It works as an excellent flatten() method: nested_list =

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Steven D'Aprano
Rick Johnson wrote: On Friday, February 8, 2013 9:16:42 AM UTC-6, Steven D'Aprano wrote: Rick Johnson wrote: GvR has always been reluctant to incorporate full OOP machinery for some reason. Python is a fully object oriented language. It is *more* object oriented than, say, Java. Oh

Re: Implicit conversion to boolean in if and while statements

2013-02-08 Thread Chris Angelico
On Sat, Feb 9, 2013 at 12:29 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Fri, Feb 8, 2013 at 5:49 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: What the hell? Oh yeah, you must be using pike again. No, if it were pike the list would look like this: ({({q}), ({w,e}), ({r,t,u}),

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Rick Johnson
On Monday, July 16, 2012 7:43:47 PM UTC-5, Steven D'Aprano wrote: [...] If I insist on making a single object do duty for both the jar and the jellybean count, then I need a null jar object, and I probably end up with something like this: Jar(number_of_beans=None) = null jar object

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Rick Johnson
On Monday, July 16, 2012 8:45:51 PM UTC-5, rusi wrote: On Jul 15, 9:50 pm, Rick Johnson rantingrickjohn...@gmail.com wrote: I think this issue is not so much a bool test vs type test, but more an ambiguous syntax issue. If you know some English, its clear that if and while create bool

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Chris Angelico
On Fri, Feb 8, 2013 at 4:53 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: And which Univeristy would you recommend for studying the intricacies of gobbledygook? ;-) Dunno, where'd you get your degree in logic? *dives for cover* ChrisA --

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Rick Johnson
On Monday, July 16, 2012 11:18:28 PM UTC-5, Devin Jeanpierre wrote: On Mon, Jul 16, 2012 at 12:03 AM, Steven D'Aprano wrote: On Sun, 15 Jul 2012 22:15:13 -0400, Devin Jeanpierre wrote: For example, instead of if stack: or if bool(stack):, we could use if stack.isempty():. This line tells

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Rick Johnson
On Tuesday, July 17, 2012 8:35:09 PM UTC-5, alex23 wrote: On Jul 17, 6:23 pm, Andrew Berg bahamutzero8...@gmail.com wrote: On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Michael Torrie
On 02/07/2013 11:16 PM, Rick Johnson wrote: He is so accustomed to guessing that it has become second nature for him. I think most of us are guessing as to what you're talking about since you're responding to a 7 month old thread that I think most people have long since deleted from their

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Rick Johnson
On Tuesday, July 17, 2012 8:35:09 PM UTC-5, alex23 wrote: On Jul 17, 6:23 pm, Andrew Berg bahamutzero8...@gmail.com wrote: On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Rick Johnson
On Friday, February 8, 2013 12:27:09 AM UTC-6, Michael Torrie wrote: On 02/07/2013 11:16 PM, Rick Johnson wrote: He is so accustomed to guessing that it has become second nature for him. I think most of us are guessing as to what you're talking about since you're responding to a 7 month

Re: Implicit conversion to boolean in if and while statements

2013-02-07 Thread Steven D'Aprano
Rick Johnson wrote: Why even have a damn bool function if you're never going to use it? bool is for converting arbitrary objects into a canonical True or False flag. E.g. one use-case is if you wish to record in permanent storage a flag, and don't want arbitrary (possibly expensive) objects to

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Steven D'Aprano
On Mon, 16 Jul 2012 11:13:33 -0700, Ethan Furman wrote: Steven D'Aprano wrote: On Sun, 15 Jul 2012 10:19:16 -0600, Ian Kelly wrote: On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano wrote: (For the record, I can only think of one trap for the unwary: time objects are false at *exactly*

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Steven D'Aprano
On Tue, 17 Jul 2012 00:18:28 -0400, Devin Jeanpierre wrote: On Mon, Jul 16, 2012 at 12:03 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 15 Jul 2012 22:15:13 -0400, Devin Jeanpierre wrote: For example, instead of if stack: or if bool(stack):, we could use if

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Steven D'Aprano
On Tue, 17 Jul 2012 00:19:48 -0500, Andrew Berg wrote: To put it in duck-typing terms, why should everything have to quack like True or False? Sure, I can see why 1 quacks like True or [] quacks like False, but I don't see why say, a Logger or function should quack like either. The default

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread John Nagle
On 7/15/2012 1:34 AM, Andrew Berg wrote: This has probably been discussed before, but why is there an implicit conversion to a boolean in if and while statements? if not None: print('hi') prints 'hi' since bool(None) is False. If this was discussed in a PEP, I would like a link to it.

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Andrew Berg
On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are objects, they are true-like unless the default is overridden. I am aware of the

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Chris Angelico
On Tue, Jul 17, 2012 at 6:23 PM, Andrew Berg bahamutzero8...@gmail.com wrote: On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Devin Jeanpierre
On Tue, Jul 17, 2012 at 2:25 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: It already is part of the collection interface: it is spelled __nonzero__ (Python 2) or __bool__ (Python 3), and like all dunder methods, it is called automatically for you when you use the right

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Ethan Furman
Andrew Berg wrote: To put it in duck-typing terms, why should everything have to quack like True or False? Sure, I can see why 1 quacks like True or [] quacks like False, but I don't see why say, a Logger or function should quack like either. Should a Thread object be True if it's been started

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Laszlo Nagy
On 2012-07-17 10:23, Andrew Berg wrote: I don't want that, but I am suggesting that it would be consistent with the idea of something or nothing. Don't confuse names and objects. You can only test the truth value of objects. If you don't have a name in a namespace, then it means you don't have

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Laszlo Nagy
Not really. It doesn't quack like anything. Actually, there is no it. So we cannot talk about how it quacks. :-D -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Terry Reedy
On 7/17/2012 4:23 AM, Andrew Berg wrote: On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are objects, they are true-like unless the

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread alex23
On Jul 17, 6:23 pm, Andrew Berg bahamutzero8...@gmail.com wrote: On 7/17/2012 2:08 AM, Steven D'Aprano wrote: The default behaviour is that every object is something, hence true-like, unless explicitly coded to be treated as false-like. Since both loggers and functions are objects, they are

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Chris Angelico
On Mon, Jul 16, 2012 at 2:53 PM, Ranting Rick rantingrickjohn...@gmail.com wrote: if obj is in essence doing if bool(obj) behind the scenes. My question is: Why hide such valuable information from the reader? It's obvious that if bool(obj) will return a boolean; whereas if obj is ambiguous.

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Chris Angelico
On Mon, Jul 16, 2012 at 3:03 PM, Ranting Rick rantingrickjohn...@gmail.com wrote: But if you are going to argue that if obj is *explicit enough*, then apply your argument consistently to String+1.75 also. Why must we be explicit about string conversion BUT not boolean conversion? Can you

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Mark Lawrence
On 16/07/2012 04:05, Chris Angelico wrote: On Mon, Jul 16, 2012 at 12:58 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: And that, the reason given in the sentence above, is the reason that we, collectively all programmers, should prefer to be explicit, not merely conveying

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread alex23
On Jul 16, 2:53 pm, Ranting Rick rantingrickjohn...@gmail.com wrote: if obj is in essence doing if bool(obj) behind the scenes. My question is: Why hide such valuable information from the reader? If @decorator is in essence doing function = decorator(function) behind the scenes, why hide that?

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread alex23
On Jul 16, 3:03 pm, Ranting Rick rantingrickjohn...@gmail.com wrote: But if you are going to argue that if obj is *explicit enough*, then apply your argument consistently to String+1.75 also. Why must we be explicit about string conversion BUT not boolean conversion? What _other_ than booleans

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Sun, 15 Jul 2012 22:03:52 -0700, Ranting Rick wrote: But if you are going to argue that if obj is *explicit enough*, then apply your argument consistently to String+1.75 also. Why must we be explicit about string conversion BUT not boolean conversion? The problem with String + 1.75 is not

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Sun, 15 Jul 2012 19:41:34 -0700, Ranting Rick wrote: Short circuitry is a powerful tool! But why the heck would your sequences ever be None? Are you using None as a default? And if so, why not use an empty sequence instead ([], {}, )? Mostly for explicitness. I want to be able to say that

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Serhiy Storchaka
On 15.07.12 19:50, Rick Johnson wrote: We must NEVER present if in such confusing manner as ExampleA. ## EXAMPLE C ## py if bool(money) == True: ... do_something() -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Albert van der Horst
In article b2971c4d-0769-4d03-a7b6-c527629a8...@x39g2000yqx.googlegroups.com, Ranting Rick rantingrickjohn...@gmail.com wrote: We DON'T want Python to silently convert cost to a string. What we DO want is to force the author to use the str function thereby making the conversion explicit. We do

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Albert van der Horst
In article 50038364$0$29995$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 15 Jul 2012 18:21:06 -0700, Ranting Rick wrote: If HOWEVER we want to truth test an object (as in: if obj) we should be FORCED to use the bool! Why? Because

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Ethan Furman
Steven D'Aprano wrote: On Sun, 15 Jul 2012 10:19:16 -0600, Ian Kelly wrote: On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano wrote: (For the record, I can only think of one trap for the unwary: time objects are false at *exactly* midnight.) Ugh, that's irritating. I can't think of any

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/15/2012 9:38 PM, Steven D'Aprano wrote: I would expect None to mean doesn't exist or unknown or something like that - e.g., a value of 0 means 0 jelly beans in the jar and None means there isn't a jar. How you interpret some_variable = None depends on what some_variable represents. If

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Ethan Furman
Andrew Berg wrote: On 7/15/2012 9:38 PM, Steven D'Aprano wrote: I would expect None to mean doesn't exist or unknown or something like that - e.g., a value of 0 means 0 jelly beans in the jar and None means there isn't a jar. How you interpret some_variable = None depends on what

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Laszlo Nagy
... Traceback (most recent quip last): Author: DeAprano, line 7, in post LogicalFallacyError: Reductio ad absurdum Deary deary me Rick. Reductio ad adsurdum is not a fallacy. It is a counter-argument to an argument or claim, by showing that the premise of the original claim leads to an

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Laszlo Nagy
This syntax is explicit *enough*. We don't need to be any more explicit. But if you are going to argue that if obj is *explicit enough*, then apply your argument consistently to String+1.75 also. Why must we be explicit about string conversion BUT not boolean conversion? Can you reduce this to

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 13:54:32 -0700, Ethan Furman wrote: Andrew Berg wrote: On 7/15/2012 9:38 PM, Steven D'Aprano wrote: I would expect None to mean doesn't exist or unknown or something like that - e.g., a value of 0 means 0 jelly beans in the jar and None means there isn't a jar. How

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Tue, 17 Jul 2012 01:12:47 +, Steven D'Aprano wrote: It looks like Firebird implements the variety of ternary logical called Keene logic. Oops, I meant Kleene. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 13:28:14 -0400, Dennis Lee Bieber wrote: On 16 Jul 2012 02:38:35 GMT, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info declaimed the following in gmane.comp.python.general: On Sun, 15 Jul 2012 12:02:37 -0500, Andrew Berg wrote: Okay, I see the value in this,

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/15/2012 3:28 PM, Terry Reedy wrote: Because everything does (or should). I can see how truth testing for empty values is convenient, but perhaps objects should only have a truth value if explicitly given one - particularly in cases where such a value wouldn't be obvious or the obvious value

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread rusi
On Jul 15, 9:50 pm, Rick Johnson rantingrickjohn...@gmail.com wrote: On Sunday, July 15, 2012 11:19:16 AM UTC-5, Ian wrote: On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: (For the record, I can only think of one trap for the unwary: time

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/16/2012 7:43 PM, Steven D'Aprano wrote: The existence of a jar or no jar is irrelevant to the question of how many jellybeans there are. They are two different things, and therefore need two different values. There are many ways to implement this. I have a better real example, but I

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Chris Angelico
On Tue, Jul 17, 2012 at 11:57 AM, Andrew Berg bahamutzero8...@gmail.com wrote: I could do: if has_message: send('{command} {args} :{message}') else: send('{command} {args}') but then I'd have to make sure has_message stays accurate since message won't necessarily be. Or

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 20:22:18 -0500, Andrew Berg wrote: On 7/15/2012 3:28 PM, Terry Reedy wrote: Because everything does (or should). I can see how truth testing for empty values is convenient, but perhaps objects should only have a truth value if explicitly given one - particularly in cases

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Devin Jeanpierre
On Mon, Jul 16, 2012 at 12:03 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 15 Jul 2012 22:15:13 -0400, Devin Jeanpierre wrote: For example, instead of if stack: or if bool(stack):, we could use if stack.isempty():. This line tells us explicitly that stack is a

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Chris Angelico
On Tue, Jul 17, 2012 at 2:18 PM, Ranting Rick rantingrickjohn...@gmail.com wrote: On Jul 16, 11:11 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: I imagine though that the Python dev's answer will basically be #2: it isn't a container, it just behaves a little bit like a

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2012 20:57:43 -0500, Andrew Berg wrote: I have a better real example, but I opted not to use it before since it requires some explanation - IRC messages. A client-to-server message has the basic form of b'COMMAND arguments :message' (e.g. b'PRIVMSG #channel :hi guys!'). Some

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/16/2012 11:11 PM, Steven D'Aprano wrote: If you are right that SimpleNamespace should be treated as a container, then it should implement container semantics. Since it doesn't, that is either: 1) a bug; or 2) a triumph of laziness over correctness I imagine though that the Python

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Andrew Berg
On 7/16/2012 11:39 PM, Steven D'Aprano wrote: If you need three (or four, or fifty) distinguishable states, then obviously boolean context will not solve your problem. I never said it would. That is the impression I got from this statement: How you interpret some_variable = None depends on

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Chris Angelico
On Sun, Jul 15, 2012 at 6:34 PM, Andrew Berg bahamutzero8...@gmail.com wrote: Converting 0 and 1 to False and True seems reasonable, but I don't see the point in converting other arbitrary values. It's for convenience. Unfortunately, not all languages treat all types the same way. It's very

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Stefan Behnel
Andrew Berg, 15.07.2012 10:34: This has probably been discussed before, but why is there an implicit conversion to a boolean in if and while statements? There isn't. This has nothing to do with if or while. All objects have a truth value in Python, evaluating to True by default (object),

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Steven D'Aprano
On Sun, 15 Jul 2012 03:34:46 -0500, Andrew Berg wrote: This has probably been discussed before, By the hoary hosts of Hoggoth, has it ever! but why is there an implicit conversion to a boolean in if and while statements? It's nothing to do with if and while. All Python objects are

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Ian Kelly
On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: (For the record, I can only think of one trap for the unwary: time objects are false at *exactly* midnight.) Ugh, that's irritating. I can't think of any scenario where I would ever want the semantics

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Rick Johnson
On Sunday, July 15, 2012 11:19:16 AM UTC-5, Ian wrote: On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: (For the record, I can only think of one trap for the unwary: time objects are false at *exactly* midnight.) Ugh, that's irritating. I can't

Re: Implicit conversion to boolean in if and while statements

2012-07-15 Thread Andrew Berg
On 7/15/2012 5:56 AM, Steven D'Aprano wrote: 3) Rather than distinguishing true from false, a more useful dichotomy is between something and nothing. Python includes a number of ways of spelling nothing of various types, such as: None, 0, 0.0, '', [], {}, set() and nearly everything

  1   2   >