Possible Duplicate:
“ValueError: zero length field name in format” error in Python 3.0,3.1,3.2ValueError异常:在格式蟒蛇零长度字段名称
我花了几个小时试图解决这个问题,但都无济于事。我读了this guide。 我还没有找到任何示例如何做我需要的。
当我运行该脚本,我得到这个错误(部分省略):
Traceback (...):
[...]
output.write("{: > 026,.18e} {: > 026,.18e}\n".format(x,y))
ValueError: zero length field name in format.
的代码是用Python编写2.6或2.7,但我运行python 3.1。我该如何改变输出格式才能使用?
def f(x,y,a = 0.01):
return y/(a+x)-y**3
def ekspEuler(N,dat):
output = open(dat,"w")
h = 3.0/N
x,y = 0,1 #zac.pogoj
for i in range(1,N+2):
output.write("{: > 026,.18e} {: > 026,.18e}\n".format(x,y))
y += h*f(x,y)
x = i*h
output.close()
感谢您的帮助。
那么,你想要*做*什么?或者以不同的方式问,为什么你不想''{} {}“。format(x,y)'? – phihag 2012-04-07 11:43:15
我仍然得到相同的错误。 – malganis 2012-04-07 11:45:31
问题是在一个括号中有两个说明符?我省略了.18e然后我得到OverflowError:(34,'数字结果我们的范围') – malganis 2012-04-07 12:14:28