use*_*147 11 python exception stderr
我真的不知道怎么说,但是当我在python 3.2中引发异常时,'\n'没有被解析 ...
这是一个例子:
class ParserError(Exception):
def __init__(self, message):
super().__init__(self, message)
try:
raise ParserError("This should have\na line break")
except ParserError as err:
print(err)
Run Code Online (Sandbox Code Playgroud)
它的工作原理如下:
$ ./test.py
(ParserError(...), 'This should have\na line break')
Run Code Online (Sandbox Code Playgroud)
如何确保新行打印为新行?
class ParserError(Exception):
pass
Run Code Online (Sandbox Code Playgroud)
要么
print(err.args[1])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2232 次 |
| 最近记录: |