最好是一个format字符串:expr = """if ({0}.autoOverlap == 1){{
{1}.currentTime += 1;
{2}.currentTime += 1;
float $refresh_tx = {3}.translateX;
float $refresh_ty = {3}.translateY;
float $refresh_tz = {3}.translateZ;
float $refresh_rx = {3}.rotateX;
float $refresh_ry = {3}.rotateY;
float $refresh_rz = {3}.rotateZ;
}}else if({0}.autoOverlap == 0){{"
{1}.currentTime = 1;
{2}.currentTime = 1;
}}""".format(firstControl.getName(), hairSyst, nucleus, cube)
注意使用"""三重引号而不是"单引号来格式化多行字符串。在
编辑:
如果原始字符串包含{ },我们必须按照documentation对它们进行转义:6.1.3. Format String Syntax
The str.format() method and the Formatter class share the same syntax
for format strings (although in the case of Formatter, subclasses can
define their own format string syntax).
Format strings contain “replacement fields” surrounded by curly braces
{}. Anything that is not contained in braces is considered literal
text, which is copied unchanged to the output. If you need to include
a brace character in the literal text, it can be escaped by doubling:
{{ and }}.