python compilefailed什么意思,re.compile()或任何给定的Python库调用是否引发异常?...

I can't tell from the Python documentation whether the re.compile(x) function may throw an exception (assuming you pass in a string). I imagine there is something that could be considered an invalid regular expression. The larger question is, where do I go to find if a given Python library call may throw exception(s) and what those are?

解决方案

Well, re.compile certainly may:

>>> import re

>>> re.compile('he(lo')

Traceback (most recent call last):

File "", line 1, in

File "C:\Python25\lib\re.py", line 180, in compile

return _compile(pattern, flags)

File "C:\Python25\lib\re.py", line 233, in _compile

raise error, v # invalid expression

sre_constants.error: unbalanced parenthesis

The documentation does support this, in a roundabout way - check the bottom of the "Module Contents" page for (brief) description of the error exception.

Unfortunately, I don't have any answer to the general question. I suppose the documentation for the various modules varies in quality and thoroughness. If there were particular modules you were interested in, you might be able to decompile them (if written in Python) or even look at the source, if they're in the standard library.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值