Escaping a triple quoted string' newbie question
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Mar 2 05:55:51 EST 2008
En Sun, 02 Mar 2008 08:33:51 -0200, Jules Stevenson <jules at js3d.co.uk>
escribi�:
> Sorry, original post got a bit mangled, which didn't help the
> explanation at
> all, reposted stuff:
>
> Apologies if the terminology in this email is a little incorrect, I'm
> still
> finding my feet.
>
> I'm using python to generate some script for another language (MEL, in
> maya,
> specifically expressions). Maya runs python too, but unfortunately its
> expression language still has to use the maya syntax.
>
> If I pass the expression this code (excuse the double spacing, email
> seems
> to e ignoring my line breaks):
>
> #runtime code [mel]
> expRuntime="""
> float $pos[]=particleShape1.worldPosition;
>
> setAttr ("heartPP_1_"+particleShape1.particleId+".tx") $pos[0];
>
> setAttr ("heartPP_1_"+particleShape1.particleId+".ty") $pos[1];
>
> setAttr ("heartPP_1_"+particleShape1.particleId+".tz") $pos[2];
> """
> dynExpression (p, s=expRuntime, rad=1) #generate the expression
>
> Then maya errors out, however if I pass maya an 'escaped' version:
>
> expRuntime="""
> float $pos[]=particleShape1.worldPosition;\nsetAttr
> (\"heartPP_1_\"+particleShape1.particleId+\".tx\") $pos[0];\nsetAttr
> (\"heartPP_1_\"+particleShape1.particleId+\".ty\") $pos[1];\nsetAttr
> (\"heartPP_1_\"+particleShape1.particleId+\".tz\") $pos[2]; """
>
> Then all is well. My question is, is there any way to convert the first
> variable example to the second? It's a lot easier to type and on the eye.
Except for the doble-space on the first version, \n is the line separator
on both, so I'll ignore them.
"""one
two"""
is the same thing as "one\ntwo" (even on Windows). The only remaining
difference that I see is " -> \"
def mayaquote(text):
return text.replace('"', '\\"')
--
Gabriel Genellina
More information about the Python-list
mailing list