Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'messages.': 0.04; 'attribute': 0.05; 'cpython': 0.05; 'irc': 0.05; 'none,': 0.05; 'arguments': 0.07; 'exception.': 0.07; 'false,': 0.07; 'parsing': 0.07; 'undefined': 0.07; '"if': 0.09; "b''": 0.09; 'explanation': 0.09; 'subject:while': 0.09; 'value.': 0.15; '":"': 0.16; 'clears': 0.16; 'received:209.85.161.174': 0.16; 'wrote:': 0.17; 'code,': 0.18; 'windows': 0.19; 'appropriate': 0.20; 'are.': 0.22; "i'd": 0.22; 'sets': 0.23; 'least': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'leave': 0.26; '(e.g.': 0.27; 'topic': 0.27; 'question': 0.27; "d'aprano": 0.29; 'existence': 0.29; 'optional': 0.29; 'steven': 0.29; 'things,': 0.29; 'objects': 0.29; 'this.': 0.29; 'maybe': 0.29; 'basic': 0.30; 'implement': 0.32; 'channel': 0.32; 'could': 0.32; 'values.': 0.33; 'to:addr:python-list': 0.33; 'times.': 0.33; 'agree': 0.34; 'received:google.com': 0.34; 'server': 0.35; 'clear': 0.35; 'pm,': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'message-id:@gmail.com': 0.36; 'be.': 0.36; 'two': 0.37; 'rather': 0.37; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'apply': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'most': 0.61; 'real': 0.61; 'between': 0.63; 'necessarily': 0.63; 'skip:6 10': 0.63; 'different': 0.63; 'therefore': 0.65; 'obvious': 0.71; 'truth': 0.75; 'irrelevant': 0.84; 'obvious.': 0.84; 'do:': 0.91; 'rick': 0.91; 'serious': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=NGSQAIZ+a8G6MrNVX6BJnOdAPcqEg3wQMSgQFagvhRk=; b=BNxOVCJKmw06u0J/A1b7kWAnjQQqytjHmGc4BrJ3sElsSgE0deai4mvDTm+SPYY5tg NKEMcvdX8K7g/pwx5xfZ82c1wxTPG/1FSoxI/ecvuLsNWcpDVY3S5rJk/OHXlHhexnTs FYRVRMvEgg6UBQPaZeThSEYbrirGglkPq5Sze4627VqAPKTEOxgmztplma1b68ohquxT kHzHkGyjsP/wefzNcVHjCZpZ1IyP1bpZU4KnVuhQYO/Z+lnmHrjILezV7CwQda9AS/ip P5RTojYJh+hK9/dzL9MWtRvv553sgFQe8w0b1Z9WI1i5QWm7iyCIBzTJq3UbmoS7Zgjg vWEQ== Date: Mon, 16 Jul 2012 20:57:43 -0500 From: Andrew Berg User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: "comp.lang.python" Subject: Re: Implicit conversion to boolean in if and while statements References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> <50037eab$0$29995$c3e8da3$5496439d@news.astraweb.com> <50047A84.6020208@gmail.com> <5004b543$0$29978$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <5004b543$0$29978$c3e8da3$5496439d@news.astraweb.com> X-Enigmail-Version: 1.4.3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342490275 news.xs4all.nl 6939 [2001:888:2000:d::a6]:41394 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25451 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 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 commands have no message part because there is no message associated with it (e.g. b'JOIN #channel') and there is at least one where there is a big difference between a blank message (b'') and no message - b'TOPIC #channel' is a request for the topic while b'TOPIC #channel :' clears the topic since the part after the b':' is b'' (b'TOPIC #channel :Welcome to #channel' sets the topic to "Welcome to #channel"). In my code, I would have an object representing a message rather than parsing it multiple times. If the message attribute is not None, I send b'{command} {args} :{message}', otherwise b'{command} {args}'. If I considered '' falsey, either I would require all messages to have ":" (which would not actually be part of the message) or have any request to view the topic as a channel op clear the topic. This would apply to the server parsing the message as well. A few other commands have messages optional as well, but they are not as serious as TOPIC. 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 maybe I could leave message undefined and catch the appropriate exception. However, using None is the cleanest and most obvious. I know Rick likes to troll, but I do agree with him that "if something:" for arbitrary objects can be ambiguous or confusing. I don't think if/while must have True or False, but not every object has an obvious truth value. -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803