全部版块 我的主页
论坛 站务区 十一区 新手入门区
826 0
2021-01-21
幼卵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?怎么解决?
谢谢!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群