我真的不知道怎麼說,但是當我在Python 3.2引發異常,「\ n」是不是解析 ...Python的3例外,不打印新的生產線
下面是一個例子:
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)
它的工作原理是這樣的:
$ ./test.py
(ParserError(...), 'This should have\na line break')
如何確保新線印刷作爲新行?
class ParserError(Exception):
pass
或
print(err.args[1])
是否打印(err.message)做呢? – 2012-07-17 14:59:48
不,對象有 – user1530147 2012-07-17 15:04:35
Intrestingly,如果你擺脫'__init__'方法,只是除了文本打印與您的代碼沒有屬性「消息」,和換行打印正確。 – geoffspear 2012-07-17 15:13:31