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

ryles rylesny at gmail.com
Fri Jul 3 04:55:19 CEST 2009


On Jul 2, 1:25 am, Terry Reedy <tjre... at udel.edu> wrote:
> > 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

It wasn't explicit, but I think Stef meant that the global should be
added to the caller's environment, which was the reason for
sys._getframe().

Is this environment only intended for interactive use? I wonder if you
might just set things up
in a PYTHONSTARTUP script instead.



More information about the Python-list mailing list