我有这样的代码:
ab = { 'Swaroop' : 'swaroop@swaroopch.com',
'Larry' : 'larry@wall.org',
'Matsumoto' : 'matz@ruby-lang.org',
'Spammer' : 'spammer@hotmail.com'
}
print "Swaroop's address is", ab['Swaroop']
del ab['Spammer']
print '\nThere are {} contacts in the address-book\n'.format(len(ab))
for name, address in ab.items():
print 'Contact {} at {}'.format(name, address)
ab['Guido'] = 'guido@python.org'
if 'Guido' in ab:
print "\nGuido's address is", ab['Guido']我在GUI中得到了这个错误:
Traceback (most recent call last):
File "E:/Python26/cook.py", line 11, in <module>
print '\nThere are {} contacts in the address-book\n'.format(len(ab))
ValueError: zero length field name in format为什么会发生这样的事情呢?
我怎么能拥有zero length field name in format?
发布于 2014-04-07 11:25:57
在Python2.6中,您需要指定数据对应的索引,如下所示
print '\nThere are {0} contacts in the address-book\n'.format(len(ab))https://stackoverflow.com/questions/22911013
复制相似问题