What exactly is "pass"? What should it be?
Thomas Rachel
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Fri Nov 18 04:57:42 EST 2011
Am 18.11.2011 05:34 schrieb Dennis Lee Bieber:
>> def _pass(*args):
>> pass
>>
>> def long_running_process(arg1, arg2, arg_etc, report = _pass):
>> result1 = do_stuff()
>> report(result1)
>
> So this is a call to a function that just returns a None, which is
> dropped by the interpreter...
I'm not sure about this. I think, the call will be executed, but the
callee will return immediately. It is different from call being dropped.
Another optimized alternative could be to do
def long_running_process(arg1, arg2, arg_etc, report=None):
result1 = do_stuff()
if report: report(result1)
but I think that is too low benefit at the cost of too much readability.
Such a function call is
2 0 LOAD_FAST 0 (a)
3 POP_JUMP_IF_FALSE 16
6 LOAD_FAST 0 (a)
9 CALL_FUNCTION 0
12 POP_TOP
13 JUMP_FORWARD 0 (to 16)
3 >> 16 ...
as opposed to just
2 0 LOAD_FAST 0 (a)
3 CALL_FUNCTION 0
6 POP_TOP
with a call target of
1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
I don't think that a call is sooo expensive that it would make any
noticeable difference.
Thomas
BTW: Sorry, Dennis, for the private mail - I am incapable to use
Thunderbird correctly :-(
More information about the Python-list
mailing list