Global VS Local Subroutines

Friedrich Rentsch anthra.norell at bluewin.ch
Thu Feb 10 16:43:32 EST 2022


I believe to have observed a difference which also might be worth 
noting: the imbedded function a() (second example) has access to all of 
the imbedding function's variables, which might be an efficiency factor 
with lots of variables. The access is read-only, though. If the inner 
function writes to one of the readable external variables, that variable 
becomes local to the inner function.

Frederic

On 2/10/22 1:13 PM, BlindAnagram wrote:
> Is there any difference in performance between these two program layouts:
>
>    def a():
>      ...
>    def(b):
>      c = a(b)
>
> or
>
>    def(b):
>      def a():
>        ...
>      c = a(b)
>
> I would appreciate any insights on which layout to choose in which 
> circumstances.
>



More information about the Python-list mailing list