Вход на сайт
import re in jython
51 просмотров
Перейти к просмотру всей ветки
Привет всем.
Как правильно импортировать re из python-а в jython?
====================================
#import re as re
from org.python.modules import re as re
teststring=''aaa(bbb)''
sc_was_regexx=re.compile("\A([^(]+)\((?P<type>.*)\)\Z")
tempMatch=sc_was_regexx.match(teststring)
if tempMatch:
print ''\n%s\n'' % teststring
print '' 1 %s'' % tempMatch.group(1)
print '' 2 %s'' % tempMatch.group(2)
print '' 2 %s'' % tempMatch.group(''type'')
=====================================
Вариант "import re as re" работает, вариант "from org.python.modules import re as re"
выдаёт ошибку:
Traceback (innermost last):
File "regex_1.py", line 12, in ?
IndexError: group 3 is undefined
Как правильно импортировать re из python-а в jython?
====================================
#import re as re
from org.python.modules import re as re
teststring=''aaa(bbb)''
sc_was_regexx=re.compile("\A([^(]+)\((?P<type>.*)\)\Z")
tempMatch=sc_was_regexx.match(teststring)
if tempMatch:
print ''\n%s\n'' % teststring
print '' 1 %s'' % tempMatch.group(1)
print '' 2 %s'' % tempMatch.group(2)
print '' 2 %s'' % tempMatch.group(''type'')
=====================================
Вариант "import re as re" работает, вариант "from org.python.modules import re as re"
выдаёт ошибку:
Traceback (innermost last):
File "regex_1.py", line 12, in ?
IndexError: group 3 is undefined