> In a function like this: > > def f(x): > return eval("x") > > , eval uses the local function namespace, and the above works. > This is according to chapter 2.3 of the Python library ref. > > Now on my problem: When eval() is used with map, the same > mechanism takes place: > > def f(x): > return map(eval,["x"]) > > It works the same as the above, because map is a builtin function > that does not modify the frame chain, so eval finds the local > namespace. > Not so with Stackless Python (at the moment), since Stackless map > assigns an own frame to map without passing the correct namespaces > to it. (Reported by Bernd Rinn) > > Question: Is this by chance, or is eval() *meant* to function with > the local namespace, even if it is executed in the context of > a function like map() ? Map, being a built-in, is transparent to namespaces. > The description of map() does not state whether it has to pass > its surrounding namespace to the mapped function, and if one > simulates map() by writing one's own python implementation, > it will fail exactly like Stackless does today. The same > applies to apply(). So you can't simulate a built-in. > I think I should fix Stackless here, anyway? Yes. Note: beware of Jeremy's nested scopes. That adds a whole slew of namespaces! (But eval() is more crippled there.) --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4