Creating a local variable scope.

Albert van der Horst albert at
Thu Sep 24 13:33:46 CEST 2009

In article <65e8a017-abcb-49ad-8867-bc473f83e246 at>,
Bearophile  <bearophileHUGS at> wrote:
>Steven D'Aprano:
>> (3) Create an inner function, then call that.
>Several people after someone gives this anwer.
>> My personal opinion is that if you really need a local scope
>> inside a function, the function is doing too much and should be split up.
>I agree. And a way to split a function is to define an inner function,
>that's one of their main purposes. No need to add other things to the
>language as the OP suggests.

There are exceptions. E.g. implementations of quicksort have a
recursive inner function, that you may prefer to not have exposed.
Also there may be data to communicate to or between instances of
the inner function.

At least that is the situation in most languages. I would be
interested to learn if and how Python gets around that.


Groetjes Albert

Economic growth -- being exponential -- ultimately falters.
albert at spe&ar& &=n

More information about the Python-list mailing list