首页 > 解决方案 > 尝试创建表时出现“ValueError:格式中的零长度字段名称”

问题描述

我在 python 脚本中有这些代码行,当我执行时,我总是得到错误:

“ValueError:格式中的零长度字段名称”

对于包含 .format(...) 命令的每一行。

# Construct info table (debugging)                                                                                                                                    
table  = []
align  = "{:>6} {:^10} {:>10} {:>10} {:>10} {:^3} {:<10}"
header = align.format("#", "xLow", "x", "xUp", "Purity", "+/-", "Error") #Purity = 1-EWK/Data                                                                         
hLine  = "="*70
table.append("")
table.append(hLine)
table.append("{:^70}".format("TGraph"))
table.append(header)
table.append(hLine)

# For-loop: All values x-y and their errors                                                                                                                           
for i, xV in enumerate(x, 0):
    row = align.format(i+1, "%.2f" % xerrl[i], "%.2f" %  x[i], "%.2f" %  xerrh[i], "%.3f" %  y[i], "+/-", "%.3f" %  yerrh[i])
    table.append(row)
table.append(hLine)

难道我做错了什么?我错过了什么?

最好的问候, 玛丽娜

标签: python

解决方案


推荐阅读