我使用这个 python shell 来生成一个字符串:
I use this python shell to generate a string:
>>>':'.join("{:x}
".format(random.randint(0, 2**16 - 1)) for i in range(4))
当我在 Python2.7.5 中运行这个 shell 时,一切正常.但是当 Python 版本为 2.6.6 时会发生 ValueError: zero length field name in format.当 Python 版本为 2.6.6 时,我应该怎样运行这个 shell?
When I run this shell in Python2.7.5, everything goes okay. But it occurs ValueError: zero length field name in format when Python version is 2.6.6. What should I run this shell fine when Python version is 2.6.6?
在 Python 2.6 或更早的版本中,您需要显式地为格式字段编号:
In Python versions 2.6 or earlier, you need to explicitly number the format fields:
':'.join("{0:x}
".format(random.randint(0, 2**16 - 1)) for i in range(4))
# ^
您可以在 docs 中阅读相关内容:
You can read about this in the docs:
在 2.7 版中更改:位置参数说明符可以省略,因此 '{} {}' 等效于 '{0} {1}'.
Changed in version 2.7: The positional argument specifiers can be omitted, so
'{} {}'is equivalent to'{0} {1}'.
这篇关于ValueError:Python2.6.6 格式中的零长度字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何制作一个在 Python 中提供角色的不和谐机器人How to make a discord bot that gives roles in Python?(如何制作一个在 Python 中提供角色的不和谐机器人?)
Discord 机器人没有响应命令Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
你能得到“关于我"吗?Discord 机器人的功能?Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“关于我吗?Discord 机器人的功能?(不和谐.py))
message.channel.id Discord PYmessage.channel.id Discord PY(message.channel.id Discord PY)
如何在 heroku 上托管我的 discord.py 机器人?How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 机器人?)
discord.py - 自动更改角色颜色discord.py - Automaticaly Change an Role Color(discord.py - 自动更改角色颜色)