Use the format method
#!/usr/bin/env python
# -*-coding: utf8-*-
from __future__ import unicode_literals, print_function, division
template = str("""<Result Type="PkFilter" Name="{RowNum:0>2d}"
Color="{Color}" Show="0" MinIntensity="0"
IntensityThreshold="100" AbsIntens="0"
LogScale="0" MinMass="{MinMass}"
MaxMass="{MaxMass}" Integrate="1"
UsePercentile="0"
IntensityPercentile="0.95"
FindMass="0" RelMass="1"></Result>""").replace("\n", " ")
def result(RowNum, MinMass, MaxMass, Color=str("#0000ff")):
return template.format(
RowNum = int(RowNum),
MinMass = repr(float(MinMass)), # repr instead of str to keep floating precision
MaxMass = repr(float(MaxMass)),
Color = Color,
)
if __name__ == "__main__":
print(result(5, 3.14, 31.4))
Gribouillis
Posting Maven
3,101 posts since Jul 2008
Reputation Points: 1,130
Solved Threads: 761
Skill Endorsements: 11
It is at the end of line 5 in the snippet above. You can also read this thread
Gribouillis
Posting Maven
3,101 posts since Jul 2008
Reputation Points: 1,130
Solved Threads: 761
Skill Endorsements: 11
Question Answered as of 4 Months Ago by
Gribouillis
and
rrashkin