Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Tim Chase Newsgroups: comp.lang.python Subject: Re: How to make Python interpreter a little more strict? Date: Sun, 27 Mar 2016 15:32:36 -0500 Lines: 36 Message-ID: References: <20160325150608.21c3827a@fujitsu> <56f7536b$0$22140$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de vzyoZ1HrsuAP1OyOhG7FaAYBYnPFpu4+Nkm/SgLbqQqQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'exist,': 0.07; 'subject:How': 0.09; 'exist.': 0.09; 'nameerror:': 0.09; 'def': 0.13; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'nameerror': 0.16; 'received:10.122': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:make': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'parameter': 0.22; 'tried': 0.24; 'header:In-Reply- To:1': 0.24; "i've": 0.25; "doesn't": 0.26; 'question': 0.27; 'function': 0.28; 'raise': 0.29; 'print': 0.30; 'code': 0.30; "d'aprano": 0.33; 'steven': 0.33; 'similar': 0.33; 'case,': 0.34; 'except': 0.34; 'next': 0.35; 'fail': 0.35; 'quite': 0.35; 'but': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'two': 0.37; 'charset:us-ascii': 0.37; '(with': 0.38; 'test': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'some': 0.40; 'subject:more': 0.61; "they're": 0.66; 'useful.': 0.72; 'intrigued': 0.84; 'received:23': 0.84 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1459110967231:2708064406 X-MC-Ingress-Time: 1459110967231 In-Reply-To: <56f7536b$0$22140$c3e8da3$5496439d@news.astraweb.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105872 On 2016-03-27 14:28, Steven D'Aprano wrote: > > So intrigued by this question I tried the following > > def fnc( n ): > > print "fnc called with parameter '%d'" % n > > return n > > > > for i in range(0,5): > > if i%2 == 0: > > fnc > > next > > print i > > > > and got the same result as the OP > > In this case, the two lines "fnc" and "next" simply look up the > function names, but without actually calling them. They're not > quite "no-ops", since they can fail and raise NameError if the name > doesn't exist, but otherwise they might as well be no-ops. Which is actually useful. I've got some 2.4 code that reads try: any except NameError: def any(...): ... (with a similar block for all() ) I don't want to call any() or all(), I simply want to test whether they exist. -tkc