我觉得这种行为很奇怪。我的代码在 Eclipse-Pydev 中有效,但在 Unix 中无效。有人可以告诉我哪里出错了吗?
代码
#!/usr/bin/python
def myDisplay(Message,File):
print "Message",Message
print len(Message)
print "File",File
print "**",'{:^48}'.format(Message),"**"
print "**",'{:^48}'.format(File),"**"
myDisplay('Success','ABC.2013-07-05_00:00:00.txt')
Unix 中的错误
Message Success
7
File ABC.2013-07-05_00:00:00.txt
**
Traceback (most recent call last):
File "DailyCheck.py", line 8, in <module>
myDisplay('Success','ABC.2013-07-05_00:00:00.txt')
File "DailyCheck.py", line 6, in myDisplay
print "**",'{:^48}'.format(Message),"**"
ValueError: zero length field name in format
Eclipse-Pydev 中的输出
Message Success
7
File ABC.2013-07-05_00:00:00.txt
** Success **
** ABC.2013-07-05_00:00:00.txt **
我很困惑我哪里出错了。格式中的字段名称不是零长度,为什么会抛出错误呢?