Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Adding an object to the global namespace through " f_globals" isthat allowed ?

Reply
Thread Tools

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

 
 
Stef Mientki
Guest
Posts: n/a
 
      07-01-2009
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
 
Reply With Quote
 
 
 
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      07-03-2009
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
>>> def foo():

.... global a
.... a = 42
....
>>> a

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> foo()
>>> a

42
>>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why defining a constant in a method is not allowed but usingself.class.const_set is allowed? Iñaki Baz Castillo Ruby 13 05-01-2011 06:09 PM
Re: Adding an object to the global namespace through " f_globals"is that allowed ? Terry Reedy Python 3 07-03-2009 08:15 AM
While executing the class definition which object is referenced bythe first argument of the class method, Y r Object attributes not allowed asdefault arguments Krishna Python 4 03-07-2008 09:44 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM



Advertisments