python 脚本IndexError: tuple index out of range

来源:互联网 发布:php充值提现网站源码 编辑:程序博客网 时间:2024/06/06 22:46

在python脚本里面使用正则时,.format会报错IndexError: tuple index out of range,

例如:‘’‘ regexp_extract(parse_url(url,'PATH'),'/detail/([^(this.?)]{32}+)',1) ’‘’.format(start_date=start_date)

原因是{32}在format格式化时,会把{32}格式化为元组,

解决方法一:

'''

......

regexp_extract(parse_url(url,'PATH'),'/detail/([^(this.?)]{num}+)',1)

......'''.format(num='{32}')

将32 使用num代替。


解决方法二:‘’‘regexp_extract(parse_url(url,'PATH'),'/detail/([^(this.?)]{{32}}+)',1)’‘’

0 0
原创粉丝点击