[英]ValueError: zero length field name in format in Python2.6.6
I use this python shell to generate a string: 我用这个python shell生成一个字符串:
>>>':'.join("{:x}\n".format(random.randint(0, 2**16 - 1)) for i in range(4))
When I run this shell in Python2.7.5, everything goes okay. 当我在Python2.7.5中运行这个shell时,一切都顺利。 But it occurs
ValueError: zero length field name in format
when Python version is 2.6.6
. 但它出现
ValueError: zero length field name in format
Python版本为2.6.6
时ValueError: zero length field name in format
。 What should I run this shell fine when Python version is 2.6.6
? 当Python版本为
2.6.6
时,我应该如何运行此shell?
In Python versions 2.6 or earlier, you need to explicitly number the format fields: 在Python 2.6或更早版本中,您需要显式编号格式字段:
':'.join("{0:x}\n".format(random.randint(0, 2**16 - 1)) for i in range(4))
# ^
You can read about this in the docs : 您可以在文档中阅读此内容:
Changed in version 2.7: The positional argument specifiers can be omitted, so
'{} {}'
is equivalent to'{0} {1}'
.版本2.7中已更改:位置参数说明符可以省略,因此
'{} {}'
等效于'{0} {1}'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.