[Tutor] Named-value formatting fails
Tim Johnson
tim at johnsons-web.com
Sun Jan 9 02:24:37 CET 2011
I'm using 2.6.5 on ubuntu 10.04.
I'm evaluating a very large string using a named-value formatting
scheme. The process fails with the following error message:
"""not enough arguments for format string"""
In the first place, I wouldn't expect to even see this error
message, because as the python documentation says:
"""
Python calls the get-item method of the right-hand-side mapping
(__getitem__), when the righthand side is an instance object.
"""
As for the right-hand mapping - I'm using the following:
class Evalx:
def __init__(self, localvals = None, globalvals = None):
if localvals is None:
self.locals = sys._getframe(1).f_locals
else :
self.locals = locals
if globalvals is None:
self.globals = sys._getframe(1).f_globals
else :
self.globals = globals
def __getitem__(self,key):
return eval(key,self.globals,self.locals)
the implementation looks like this:
self.content = content % Evalx()
I would really appreciate some insights on this issue.
I don't really know how to debug this, except for to look for some
"%s" in the `content' string.
TIA
--
Tim
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
More information about the Tutor
mailing list