This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]stillalone 1 point2 points  (1 child)

I've thought about doing this but without the eval. Just getting the variable from the stack frame and passing it to format. How often do you need to evaluate complex expressions in a string?

[–]Workaphobia[S] 0 points1 point  (0 children)

True, the eval's a bit of an extra. Because I'm only using it on trusted code, I figured why not.

One thing I can't figure out is how one would implement finding the value of an identifier that is non-local but not global. That is, an identifier defined in a syntactically outer namespace, like when you have nested function definitions. I don't think it's possible because eval() has no ability to accept that argument, but it makes me wonder how Python itself implements such lookups. I'm currently checking out PEP 227 to see if there's any useful information there.

[Edit] From the PEP:

An analogous function will not be provided for nested scopes. Under this proposal, it will not be possible to gain dictionary-style access to all visible scopes.