【发布时间】:2020-11-14 12:14:38
【问题描述】:
我在 Windows 10 上使用 Python 3.8.3。我有以下代码:
import # all the necessary modules
try:
# do something
except WebDriverException:
print(sys.exc_info()[0])
出现异常时,我收到以下信息:
<class 'selenium.common.exceptions.SessionNotCreatedException'>
如何让print() 只输出<class> 中的字符串?:
selenium.common.exceptions.SessionNotCreatedException
任何帮助将不胜感激。
【问题讨论】:
-
except WebDriverException as exc: print(type(exc))? -
@jonrsharpe 打印出的内容与
print(sys.exc_info()[0])完全相同。我只想在. 之后输出字符串 -
.__name__?见stackoverflow.com/questions/510972/… -
@jonrsharpe 我也试过了。下面的第一个答案是用
__name__修改的,但它只给出SessionNotCreatedException。哪个很接近,但不是确切的字符串。 -
然后参见例如stackoverflow.com/q/2020014/3001761 - 这里的context是什么,你用它做什么,你已经做了什么研究?
标签: python python-3.x windows