from future import pass_function

Chris Angelico rosuav at gmail.com
Wed Jul 25 12:05:39 EDT 2012


On Wed, Jul 25, 2012 at 6:40 PM, Ulrich Eckhardt
<ulrich.eckhardt at dominolaser.com> wrote:
> I just had an idea, it occurred to me that the pass statement is pretty
> similar to the print statement, and similarly to the print() function, there
> could be a pass() function that does and returns nothing.
>
> Example:
>    def pass():
>        return
>
>    try:
>        do_something()
>    except:
>        pass()

Except that "pass" is a syntactic construct that basically says "hey,
I have an indented block here, but there's no code in it". It's not
executable any more than the syntactic token "INDENT" is. It's more
closely related to the colon at the end of "try" than it is to the
"do_something()" call.

By comparison, Python 2's print statement is executable. It causes
real action to happen at run-time. It makes sense to pass "print" as
an argument to something; for instance:

def some_generator():
   yield blah

map(print,some_generator())

Simple way of making the iterator display its yielded result. I cannot
imagine any circumstance in which you'd want to map "pass" over
everything. But then, as Teresa said, I'm only one, and possibly I'm
wrong!

ChrisA



More information about the Python-list mailing list