[Python-ideas] A "local" pseudo-function

MRAB python at mrabarnett.plus.com
Tue May 1 14:08:02 EDT 2018


On 2018-05-01 16:23, Steven D'Aprano wrote:
> On Mon, Apr 30, 2018 at 08:52:13PM -0500, Tim Peters wrote:
> 
>> > Would/should it be possible to inject a name into a local scope? You can't
>> > inject into a function scope, and names in a function scope can be
>> > determined statically (they are allocated slots), so could the same kind of
>> > thing be done for names in a local scope?
>> 
>> Sorry, I'm unclear on what "inject a name into a local scope" means.
>> Do you mean at runtime?
> 
> I don't know what MRAB means by "inject", but I know what *I* mean, and
> I have a real use-case for it.
> 
By "inject" I mean putting a name into a namespace:

     import my_module
     my_module.foo = 'FOO'

You can't insert a name into a function's body to make a new local variable.

[snip]


More information about the Python-ideas mailing list