看起来单个
str.format呼叫是不可能的.
它不会那么漂亮,但你可以简单地添加另一个:
# Regular Python's scientific notation, split up to coefficient and exponent.
x, e = "{:1.7E}".format(timepoint).split("E")
# Format again: coefficient first, then sign, then padded "sign-less" exponent.
strTimepoint = "{}E{}{:0>3}".format(x, e[0], e[1:])
当然,强烈建议将其全部包装在一个函数中(根据您的需要调整名称):
def foo(timepoint):
# Regular Python's scientific notation, split up to coefficient and
# exponent.
x, e = "{:1.7E}".format(timepoint).split("E")
# Format again: coefficient first, then sign, then padded "sign-less"
# exponent.
return "{}E{}{:0>3}".format(x, e[0], e[1:])
foo(6) # '6.0000000E+000'
foo(12) # '1.2000000E+001'
foo(1e123) # '1.0000000E+123'