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

S

Stef Mientki

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


thanks,
Stef Mientki
 
B

Bruno Desthuilliers

Stef Mientki a écrit :
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

Anything wrong with the 'global' statement ?

Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
pythonrc start
pythonrc done.... global a
.... a = 42
....Traceback (most recent call last):
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,244
Members
46,838
Latest member
KandiceChi

Latest Threads

Top