【发布时间】:2018-12-17 10:22:29
【问题描述】:
我必须将代码从 Python2.x 转换为 Python3(主要是字符串格式) 我遇到了这样的事情:
Logger.info("random String %d and %i".format(value1, value2))
现在,我知道 %d 可以替换为 {:d} 但找不到等效的 %i(已签名) 使用 {:i} 会出现以下错误:
ValueError:“int”类型对象的未知格式代码“i”
【问题讨论】:
-
stackoverflow.com/questions/22617/… 可能会给你答案。
-
另请参阅:stackoverflow.com/questions/4148790/… - 您最好不要自己进行格式化。
-
而
"%d".format(value)甚至不应该正常工作。它应该是"%d" % value"或"{:d}".format(value)"(或简单的"{}".format(value))。
标签: python python-3.x string-formatting