【发布时间】:2020-10-28 02:35:31
【问题描述】:
我在 Windows 上使用 python 3.7.7。我正在尝试制作一种高尔夫语言。在那个 e。如果您像这样引发异常(明确NameError):
raise NameError("Your input was not recognized as a function, variable or datatype")
然后程序自动退出。 当我尝试这个时:
print(NameError("Your input was not recognized as a function, variable or datatype"))
然后它会打印错误但不完全并且不是这样的红色:
Your input was not recognized as a function, variable or datatype
有没有办法让程序不退出并打印真正的错误?
【问题讨论】:
-
而程序在打印错误后应该怎么做?
-
如果你只关心颜色,那么你可以使用像colorize这样的包
-
您好,您是否考虑过使用 try ... catch 语句。如果你提供一个你想要做什么的例子,那么很容易说明 try catch 语句是如何适应它的。最好的问候
-
@wovano 应该会继续正常
-
@MZ 我尝试了所有的着色包,但打印的内容类似于
hello[1]re[[3]
标签: python python-3.x python-3.7 nameerror raiseerror