Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.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; 'interpreter': 0.05; 'function,': 0.07; 'python': 0.08; '(good': 0.09; 'argument,': 0.09; 'exceptions': 0.09; 'folks,': 0.09; 'run.': 0.09; 'subprocess': 0.09; 'exception': 0.12; 'def': 0.14; 'argument': 0.15; 'syntax': 0.15; 'this:': 0.15; 'arg2,': 0.16; 'bit.': 0.16; 'bourne': 0.16; 'except:': 0.16; 'runs.': 0.16; 'subject:pass': 0.16; 'syntaxerror:': 0.16; 'cheers,': 0.18; 'wrote:': 0.18; 'example.': 0.18; 'seems': 0.19; 'trying': 0.21; 'process,': 0.21; '(or': 0.22; 'appear': 0.23; 'header:In-Reply- To:1': 0.23; 'keyword': 0.24; 'shell': 0.24; 'specify': 0.24; 'times,': 0.24; 'code': 0.25; 'statement': 0.25; 'fine': 0.26; "i'm": 0.26; 'function': 0.27; 'invalid': 0.28; 'pass': 0.28; 'idle': 0.28; 'received:199': 0.28; 'looks': 0.28; 'print': 0.29; 'do.': 0.30; 'but...': 0.30; 'colon': 0.30; 'construct': 0.30; 'object.': 0.30; 'chris': 0.30; 'example': 0.30; 'subject:?': 0.31; "i'll": 0.31; 'nov': 0.31; 'pm,': 0.31; 'thu,': 0.32; 'does': 0.32; 'to:addr:python-list': 0.32; 'actually': 0.33; 'instead': 0.33; 'there': 0.33; 'header:User-Agent:1': 0.33; '17,': 0.34; 'null': 0.34; 'pass.': 0.34; 'subject:What': 0.34; 'try:': 0.34; 'which,': 0.34; 'similar': 0.35; 'object': 0.35; 'url:python': 0.35; 'something': 0.36; 'another': 0.36; 'list,': 0.37; 'but': 0.37; 'question,': 0.38; 'else': 0.38; 'url:org': 0.38; 'url:docs': 0.38; 'define': 0.39; 'progress': 0.39; 'subject:: ': 0.39; 'might': 0.39; 'to:addr:python.org': 0.39; 'happens': 0.40; 'skip:_ 10': 0.40; 'being': 0.40; 'skip:l 20': 0.40; 'more': 0.60; 'your': 0.61; 'john': 0.62; '2011': 0.62; 'accepts': 0.64; 'ever': 0.65; 'supply': 0.68; 'care': 0.70; 'are)': 0.84; 'effectively:': 0.84; 'subject:should': 0.84; 'url:reference': 0.84 X-IronPort-AV: E=McAfee;i="5400,1158,6533"; a="136423068" Date: Thu, 17 Nov 2011 19:01:01 -0800 From: Dominic Binks User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: What exactly is "pass"? What should it be? References: <27955957.352.1321582691251.JavaMail.geo-discussion-forums@prap37> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed 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: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321585339 news.xs4all.nl 6940 [2001:888:2000:d::a6]:56751 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15852 On 11/17/2011 6:45 PM, Chris Rebert wrote: > On Thu, Nov 17, 2011 at 6:18 PM, John Ladasky wrote: >> Hi folks, >> >> I'm trying to write tidy, modular code which includes a long-running process. From time to time I MIGHT like to check in on the progress being made by that long-running process, in various ways. Other times, I'll just want to let it run. So I have a section of code which, generally, looks like this: >> >> def _pass(*args): >> pass >> >> def long_running_process(arg1, arg2, arg_etc, report = _pass): >> result1 = do_stuff() >> report(result1) >> result2 = do_some_different_stuff() >> report(result2) >> result3 = do_even_more_stuff() >> report(result3) >> return result3 >> >> This does what I want. When I do not specify a report function, the process simply runs. Typically, when I do supply a report function, it would print something to stdout, or draw an update through a GUI. >> >> But this approach seems a tad cumbersome and unPythonic to me, particularly the part where I define the function _pass() which accepts an arbitrary argument list, and does nothing but... pass. > > Seems fine to me (good use of the null object pattern), although I > might define _pass() to instead take exactly 1 argument, since that's > all you ever call report() with in your example. > >> This has led me to ask the question, what exactly IS pass? I played with the interpreter a bit. >> >> IDLE 2.6.6 ==== No Subprocess ==== >>>>> pass >>>>> pass() >> SyntaxError: invalid syntax >>>>> type(pass) >> SyntaxError: invalid syntax >> >> So, pass does not appear to be a function, nor even an object. Is it nothing more than a key word? > It is a keyword that can appear in a position where a statement is required by the grammar but there is nothing to do. For example if .. then .. else .. where nothing happens in the else condition is effectively: if : else: pass Bourne shell has a similar construct with the colon statement : Another python example is where you need to catch an exception (or all exceptions but don't actually care about what they are) try: except: pass > Correct: > http://docs.python.org/reference/simple_stmts.html#pass > http://docs.python.org/reference/lexical_analysis.html#keywords > > Cheers, > Chris -- Dominic Binks: dbinks@codeaurora.org Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum