简体   繁体   English

python版本2.7.3导入maxrepeat模块的问题

[英]Issue with python version 2.7.3 importing maxrepeat module

I am trying to import maxrepeat module in python 2.7.3 and couldn't get much information in google can some one please help. 我正在尝试在python 2.7.3中导入maxrepeat模块,但在Google中无法获取太多信息,请有人帮忙。

What is the module that helps maxrepeat module to work ? 什么是可帮助maxrepeat模块工作的模块?

I am able to import maxrepeat module using “from _sre import maxrepeat” but still fails while runnninv automation . 我能够使用“ from _sre import maxrepeat”来导入maxrepeat模块,但是在运行runnninv Automation时仍然失败。

MAXREPEAT is used internally by the re module as an upper limit for the minimum, maximum, or exact number of repetitions that can be specified in a pattern. re模块内部MAXREPEAT用作可在模式中指定的最小,最大或精确重复次数的上限。 For example: 例如:

>>> import re
>>> re.compile(r'a{100}')         # exactly 100 "a"s
<_sre.SRE_Pattern object at 0x7fa68be10780>
>>> re.compile(r'a{100, 200}')    # between 100 and 200 "a"s

Equalling or exceeding MAXREPEAT in a repetition value causes an exception to be raised by the regular expression parser in module sre_parse : 重复值MAXREPEAT或超过MAXREPEAT会导致sre_parse模块中的正则表达式解析器引发异常:

>>> from sre_constants import MAXREPEAT
>>> MAXREPEAT
4294967295L

>>> re.compile(r'a{{{}}}'.format(MAXREPEAT-1))
<_sre.SRE_Pattern object at 0x7f0ec959f660>

>>> re.compile(r'a{{{}}}'.format(MAXREPEAT))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/re.py", line 194, in compile
    return _compile(pattern, flags)
  File "/usr/lib64/python2.7/re.py", line 249, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib64/python2.7/sre_compile.py", line 572, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib64/python2.7/sre_parse.py", line 716, in parse
    p = _parse_sub(source, pattern, 0)
  File "/usr/lib64/python2.7/sre_parse.py", line 324, in _parse_sub
    itemsappend(_parse(source, state))
  File "/usr/lib64/python2.7/sre_parse.py", line 518, in _parse
    raise OverflowError("the repetition number is too large")
OverflowError: the repetition number is too large

There should not be any reason to care about MAXREPEAT with normal use of the re module. 正常使用re模块时,没有任何理由要关心MAXREPEAT If you need to handle errors then use the exception: 如果需要处理错误,请使用异常:

try:
    re.compile(r'a{{{}}}'.format(MAXREPEAT))
except OverflowError as exc:
    print 'Failed to compile pattern: {}'.format(exc.message)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM