楼主: EliteGlable
637 0

[求助] 幼python中的finditer()关于next问题求助 [推广有奖]

  • 0关注
  • 0粉丝

大专生

71%

还不是VIP/贵宾

-

威望
0
论坛币
19 个
通用积分
13.0050
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
7615 点
帖子
20
精华
0
在线时间
93 小时
注册时间
2018-2-5
最后登录
2023-5-1

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
幼卵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?怎么解决?
谢谢!

二维码

扫码加我 拉你入群

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

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

关键词:findit python ITER INDI find

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-4 10:00