Creating a local variable scope.

Albert van der Horst albert at spenarnc.xs4all.nl
Thu Sep 24 07:33:46 EDT 2009


In article <65e8a017-abcb-49ad-8867-bc473f83e246 at s39g2000yqj.googlegroups.com>,
Bearophile  <bearophileHUGS at lycos.com> 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.

>
>Bye,
>bearophile

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list