[Python-ideas] Macros for Python
Terry Jan Reedy
tjreedy at udel.edu
Wed Apr 24 16:35:50 CEST 2013
On 4/23/2013 11:49 PM, Haoyi Li wrote:
> I thought this may be of interest to some people on this list, even if
> not strictly an "idea".
>
> I'm working on MacroPy <https://github.com/lihaoyi/macropy>, a little
> pure-python library that allows user-defined AST rewrites as part of the
> import process (using PEP 302).
From the readme
'''
String Interpolation
a, b = 1, 2
c = s%"%{a} apple and %{b} bananas"
print c
#1 apple and 2 bananas
'''
I am a little surprised that you would base a cutting edge extension on
Py 2. Do you have it working with 3.3 also?
'''Unlike the normal string interpolation in Python, MacroPy's string
interpolation allows the programmer to specify the variables to be
interpolated inline inside the string.'''
Not true as I read that.
a, b = 1, 2
print("{a} apple and {b} bananas".format(**locals()))
print("%(a)s apple and %(b)s bananas" % locals())
#1 apple and 2 bananas
#1 apple and 2 bananas
I rather like the anon funcs with anon params. That only works when each
param is only used once in the expression, but that restriction is the
normal case.
I am interested to see what you do with pattern matching.
tjr
More information about the Python-ideas
mailing list