Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'else:': 0.03; 'elif': 0.05; 'mrab': 0.05; 'variables': 0.07; 'doing?': 0.09; 'english,': 0.09; '"0"': 0.16; '12:17,': 0.16; '18:13,': 0.16; 'andreas': 0.16; 'bye,': 0.16; 'does,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'sys.exit(0)': 0.16; 'then?': 0.16; 'year)': 0.16; '\xce\xb3\xce\xaf\xce\xbd\xce\xb5\xce\xb9': 0.16; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'char': 0.24; 'exists': 0.24; 'month,': 0.24; '\xce\xb4\xce\xb5\xce\xbd': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'on,': 0.29; "doesn't": 0.30; 'specified': 0.30; '\xcf\x84\xce\xbf': 0.30; '>>>>': 0.31; 'skip:c 30': 0.32; 'actual': 0.34; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'shorter': 0.36; 'var': 0.36; 'possible': 0.36; 'wrong': 0.37; 'problems': 0.38; 'skip:\xcf 20': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'how': 0.40; 'is.': 0.60; 'most': 0.60; "you're": 0.61; 'times': 0.62; 'name': 0.63; 'header:Reply-To:1': 0.67; 'of:': 0.68; 'wish': 0.70; 'reply-to:no real name:2**0': 0.71; '8bit%:100': 0.72; 'reply-to:addr:python.org': 0.84; 'subject:gets': 0.84; 'together,': 0.84; '\xce\xb1\xcf\x86\xce\xbf\xcf\x8d': 0.84; '\xce\xbf\xcf\x8d\xcf\x84\xce\xb5': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=KrN0hwmN c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=oyR3mlnJdzkA:10 a=ZBT6mux8yFEA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=tXfRgeB1Xo0A:10 a=mluK54tlpMFEtmwR-cIA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett:2500 Date: Wed, 12 Jun 2013 18:53:07 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: A certainl part of an if() structure never gets executed. References: <2bc90d3b-09c2-4315-9357-ff7f039465e0@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 125 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371059580 news.xs4all.nl 15907 [2001:888:2000:d::a6]:44770 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47826 On 12/06/2013 18:13, Νικόλαος Κούρας wrote: > On 12/6/2013 7:40 μμ, MRAB wrote: >> On 12/06/2013 12:17, Νικόλαος Κούρας wrote: >>> >>>> As with most of your problems you are barking up the wrong tree. >>>> Why not use the actual value you get from the form to check whether you >>>> have a valid month? >>>> Do you understand why "0" is submitted instead of "=========="? >>>> >>>> Bye, Andreas >>> >>> I have corrected the enumerate loop but it seems thet now the year works >>> and the selected name nad month fail: >>> >>> if '=' not in ( name and month and year ): >>> cur.execute( '''SELECT * FROM works WHERE clientsID = >>> (SELECT id FROM >>> clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = >>> %s ORDER BY lastvisit ASC''', (name, month, year) ) >>> elif '=' not in ( month and year ): >>> cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) >>> = %s and >>> YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) ) >>> elif '=' not in year: >>> cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) >>> = %s ORDER >>> BY lastvisit ASC''', year ) >>> else: >>> print( '

Πώς να γίνει αναζήτηση αφού >>> δεν επέλεξες >>> ούτε πελάτη ούτε μήνα ή τουλάχιστον το έτος?' ) >>> print( '>> content="5;/cgi-bin/pelatologio.py">' ) >>> sys.exit(0) >>> >>> >>> i tried in , not in and all possible combinations. but somehow it >>> confuses me. >>> >>> doesn't that mean? >>> >>> if '=' not in ( name and month and year ): >>> >>> if '=' does not exists as a char inside the name and month and year >>> variables? >>> >>> i think it does, but why it fails then? >>> >> You think it does, but you're wrong. > > How would you telll in english word what this is doing? > > if '=' not in ( name and month and year ): > In English, the result of: x and y is basically: if bool(x) is false then the result is x, otherwise the result is y For example: >>> bool("") False >>> "" and "world" '' >>> bool("Hello") True >>> "Hello" and "world" 'world' > > and then what this is doing? > > if '=' not in ( name or month or year ): > In English, the result of: x or y is basically: if bool(x) is true then the result is x, otherwise the result is y For example: >>> bool("") False >>> "" or "world" 'world' >>> bool("Hello") True >>> "Hello" or "world" 'Hello' These can be strung together, so that: x and y and z is equivalent to: (x and y) and z and: x or y or z is equivalent to: (x or y) or z and so on, however many times you wish to do it. > Never before i used not in with soe many variables in parenthesi, up > until now i was specified it as not in var 1 and not in var 2 and not in > var 2 and so on.... > Keep it simple: if '=' not in name and '=' not in month and '=' not in year: There may be a shorter way, but you seem confused enough as it is.