幼卵python一枚,在学习python核心编程(Wesley Chun著,孙波翔等译)中的finditer()函数时,采用python3.9
步骤如下
“>>> import re
>>> s = 'This and that.'
>>> re.finditer(r'(th\w+) and (th\w+)', s, re.I).next().groups()
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
re.finditer(r'(th\w+) and (th\w+)', s, re.I).next().groups()
AttributeError: 'callable_iterator' object has no attribute 'next'
>>> m = re.finditer(r'(th\w+) and (th\w+)', s, re.I)
>>> m = re.finditer(r'(th\w+) and (th\w+)', s, re.I)
>>> print(2, m)
2 <callable_iterator object at 0x0000025E4A1E7EE0>
>>> for g in re.finditer(r'(th\w+) and (th\w+)', s, re.I):
print(3, g.group())
print(4, g.group(1))
print(5, g.group(2))
print(6, g.groups())
3 This and that
4 This
5 that
6 ('This', 'that')
>>> m = re.findall(r'(th\w+)', s, re.I)
>>> print(7, m)
7 ['This', 'that']
>>> g = re.finditer(r'(th\w+)', s, re.I)
>>> m = g.next()
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
m = g.next()
AttributeError: 'callable_iterator' object has no attribute 'next'”
为什么属性中没有next?怎么解决?
谢谢!