
November 6th, 2004, 01:44 PM
|
|
Contributing User
|
|
Join Date: Oct 2004
Location: Isle of dogs
Posts: 68
Time spent in forums: < 1 sec
Reputation Power: 5
|
|
Quote: | Originally Posted by Grim Archon Well the docs explain it very well - I suppose if you know what a namespace is.
Global and local dictionaries can be supplied to become the namespace that the eval expression will be executed in. The local namespace is for example the definitions available within the function that is using the eval function. Global corresponds to the enclosing function, class, module and the rest.
If they are omitted then the expression has complete access to any and all variables, functions, classes and module imports that were existing in the namespace before the code is evaluated.
If you specify the global and local dictionaries then you have the ability to redefine the operating environment for the expression - possibly restricting it or changing it completely.
As to why you would do it - security is one reason, not allowing an arbitrary string obtained from wherever to cause havoc when it is evaluated.
You can use the globals() built in function, (there is also a locals() function) - to return a dictionary suitable for modifying.
grim  |
If secuirty is the only reason for those extre paramiters, I dont think I would need it. I wanted to implement control tables into my application and use eval to store functions.
Thanks for you help dude

|