Deutsch
Germany.ruФорумы → Архив Досок→ Программирование

import re in jython

51  
katran76 местный житель16.01.07 10:24
16.01.07 10:24 
Привет всем.
Как правильно импортировать 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
#1 
  Chipolino местный житель16.01.07 18:34
NEW 16.01.07 18:34 
в ответ katran76 16.01.07 10:24
Насчёт жетона не помогу :-)
Возник вопрос , какой смысл в "import re as re" ?
#2