问题:
为什么我在格式化消息时没有收到异常消息,%s但我使用了format?
失败:
>>> Exception('foo %s', 'bar').message
''
Run Code Online (Sandbox Code Playgroud)
作品:
>>> Exception('foo {}'.format('bar')).message
'foo bar'
Run Code Online (Sandbox Code Playgroud)
任何解释为什么它失败%s?
您的 %-substitution in 语法Exception不正确。您需要使用%来指定替换字符串:
>>> Exception('foo %s' % 'bar').message
'foo bar'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3131 次 |
| 最近记录: |