【发布时间】:2013-09-03 09:37:42
【问题描述】:
if re.findall(r"i am .*", a):
reg = re.compile(r" i am ([\w]+).*?$")
print('How long have you been {}?'.format(*reg.findall(a)))
所以如果我输入:
i am struggling with life...
它应该输出:
How long have you been struggling?
但由于某种原因,我得到了一个元组错误?
顺便说一句,a 只是一个输入字段。
Traceback (most recent call last):
File "program.py", line 14, in <module>
print('How long have you been {}?'.format(*reg.findall(a)))
IndexError: tuple index out of range
【问题讨论】:
标签: python regex python-3.x tuples