我知道我能做到:
try:
# do something that may fail
except:
# do this if ANYTHING goes wrong
Run Code Online (Sandbox Code Playgroud)
我也可以这样做:
try:
# do something that may fail
except IDontLikeYouException:
# say please
except YouAreTooShortException:
# stand on a ladder
Run Code Online (Sandbox Code Playgroud)
但如果我想在两个不同的例外中做同样的事情,我现在能想到的最好的就是这样做:
try:
# do something that may fail
except IDontLikeYouException:
# say please
except YouAreBeingMeanException:
# say please
Run Code Online (Sandbox Code Playgroud)
有什么办法我可以做这样的事情(因为两个例外的行动都是say please
):
try:
# do something that may fail
except IDontLikeYouException, YouAreBeingMeanException:
# say please
Run Code Online (Sandbox Code Playgroud)
现在这真的不起作用,因为它符合以下语法:
try:
# do something that may fail
except …
Run Code Online (Sandbox Code Playgroud) 在我的一些perl脚本中,我发现在我处理它们时必须启用正则表达式调试.我已经看到有一种颜色模式,但我似乎无法获得颜色输出.我已添加use re 'debugcolor';
到我的程序中,但似乎表现没有什么不同use re 'debug';
.
我想知道cmd.exe是否不支持颜色输出.我发现的任何文档都说它可以在支持它的终端上运行.
我的问题归结为:我还需要做些什么来启用颜色输出吗?或者,我可以使用什么其他终端程序代替cmd.exe?