Comment 1 for bug 343992

Revision history for this message
Jon Guyer (guyer) wrote :

A user just brought a related issue to our attention. We have an example that uses Python string substitution to build up a command for an external program (gmsh). See <http://matforge.org/fipy/browser/branches/version-2_0/examples/diffusion/circle.py#L70>.

When these lines are pasted into ipython, although everything seems to work, the string is garbled by %magic, and ultimately a very confusing error is thrown by our gmsh interpreter. For instance:

In [14]: s = """
   ....: %(radius)g;
   ....: """ % locals()

In [15]: s
Out[15]: '\n_ip.magic("1; ")\n'

whereas:

In [12]: s = "%(radius)g" % locals()

In [13]: s
Out[13]: '1'

Is there any way to get Python string substitution syntax to override %magic commands in multiline strings?