Newbie can't figure out documentation practices

Fernando Perez fperez528 at yahoo.com
Fri May 9 19:54:55 EDT 2003


Bengt Richter wrote:


> I think you may not want to use it in all environments, though:
> 
>  >>> class InterpolationDictClass:
>  ...     import sys
>  ...     def __getitem__(self, name):
>  ...         frame = sys._getframe(1)
>  ...         return eval(name, frame.f_globals, frame.f_locals)
>  ...
>  >>> idc = InterpolationDictClass()
>  >>> format =
>  >>> '%(__import__("sys").stdout.write("coulda-been-worse"))s\neh?'
>  >>> print format  % idc
>  coulda-been-worseNone
>  eh?

Oh, I know. That evil eval in there is an open door for all sorts of fun
stuff to happen.  

One more reason why (I think) there should be a newbie-friendly way of
getting my canonical

print '%(self.hello)s' % locals()

to work.  Having the cleanest (IMO) solution involve both stack frame
manipulations and an eval() is not my idea of newbie-friendly ;)

Cheers,

f.




More information about the Python-list mailing list