UserLinux chooses Python as "interpretive language" of choice

Bengt Richter bokr at oz.net
Sun Dec 21 16:51:33 EST 2003


On Sun, 21 Dec 2003 10:23:29 +0100, Peter Otten <__peter__ at web.de> wrote:

>Jarek Zgoda wrote:
>
>> Anyway, isn't that function always returns value, even without explicit
>> "return" statement?
>
>>>> import dis
>>>> def f():
>...     return 123
>...
>>>> dis.dis(f)
>  2           0 LOAD_CONST               1 (123)
>              3 RETURN_VALUE
>              4 LOAD_CONST               0 (None)
>              7 RETURN_VALUE
>>>> def g():
>...     raise Exception
>...
>>>> dis.dis(g)
>  2           0 LOAD_GLOBAL              0 (Exception)
>              3 RAISE_VARARGS            1
>              6 LOAD_CONST               0 (None)
>              9 RETURN_VALUE
>>>> def h(): pass
>...
>>>> dis.dis(h)
>  1           0 LOAD_CONST               0 (None)
>              3 RETURN_VALUE
>>>>
>
>So Python always appends a 
>
>return None
>
>statement at the end of a function.
>Of course that doesn't mean that it will be executed.

Since the latter is the case much of the time, and since then
it is just unoptimized convenience-boilerplate, maybe a single-byte
RETURN_NONE byte code could be introduced?

Regards,
Bengt Richter




More information about the Python-list mailing list