Adding an object to the global namespace through " f_globals" is that allowed ?

Stef Mientki stef.mientki at gmail.com
Sun Jul 5 11:35:14 CEST 2009


Terry Reedy wrote:
> Stef Mientki wrote:
>> hello,
>>
>> I need to add an object's name to the global namespace.
>> The reason for this is to create an environment,
>> where you can add some kind of math environment,
>> where no need for Python knowledge is needed.
>>
>> The next statement works,
>> but I'm not sure if it will have any dramatical side effects,
>> other than overruling a possible object with the name A
>>
>> def some_function ( ...) :
>>      A = object ( ...)
>>      sys._getframe(1).f_globals [ Name ] = A
>
> global name
> name = A
>
> or is name is a string var
> globals()[name] = A
great, the last 2 lines works in most cases.
Now to get everything working correctly, I have to use both globals() 
and f_globals()
but everything seems to work perfect now.

thanks for all the hints.
cheers,
Stef




More information about the Python-list mailing list