completely implicit interpolation based on a frame object

Steve Holden steve at holdenweb.com
Wed Dec 8 01:40:16 EST 2010


On 12/8/2010 2:49 AM, Edward Peschko wrote:
> All,
> 
> Ok, it looks like in order to implement a tracer that does
> interpolation, I'm going to have to hack around with frames.
> 
> Perl's interpolation is fairly straightforward, to do interpolation of
> $a == 1 all you need to do is put quotes around "$a == 1" to have $a
> evaluated.
> 
> So, I'd like to do the same thing with python. It looks like I can do
> the same thing with frames, ie:
> 
>      interpolate_frame(frame, "if not wx.Platform == '__WXMAC' ")
> 
> would interpolate wx based off of the frame that you passed to
> interpolate_frame, because wx is in the f_locals or f_globals
> dictionary.
> 
> Hence, this would become:
> 
>     loc_wx = _first_defined(frame.f_locals["wx"],     frame.f_globals["wx"])
>     return "if not ", loc_wx.Platform , " == \"__WXMAC\""
> 
> which would then do the interpolation.
> 
> I guess my question is - has something like this been released? I see
> some close hits, namely Evan Forsmark's
> http://www.evanfosmark.com/2008/06/string-interpolation-in-python/
> 
> but I don't see anything exact, and getting this right would be fairly
> tricky, so I was hoping for canned solution.
> 
> Any ideas would be great on this, including pitfalls that people see
> in implementing it.
> 
http://docs.python.org/library/string.html#template-strings

regards
 Steve
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon 2011 Atlanta March 9-17       http://us.pycon.org/
See Python Video!       http://python.mirocommunity.org/
Holden Web LLC                 http://www.holdenweb.com/




More information about the Python-list mailing list