Newbie can't figure out documentation practices
Bengt Richter
bokr at oz.net
Fri May 9 19:41:55 EDT 2003
On Fri, 09 May 2003 15:24:55 -0600, Fernando Perez <fperez528 at yahoo.com> wrote:
>sismex01 at hebmex.com wrote:
>
>> OK, this is as small as I can make it and keep it usefull:
>>
>>>>> class InterpolationDictClass:
>> def __getitem__(self, name):
>> frame = sys._getframe(1)
>> return eval(name, frame.f_globals, frame.f_locals)
>>
>>
>
>I like it :)
>
>Well, at least this round of discussions did get us the shortest possible
>implementation of a reasonable solution, which works even for nested
>objects (like a.b.c.d).
>
>I hold to my point of considering this a wart for the reasons I've given.
>But I like this solution enough to probably just make it routine in my
>coding. Then I'll stop caring and won't bring up the topic again ;)
>
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?
Regards,
Bengt Richter
More information about the Python-list
mailing list