鱼C论坛

 找回密码
 立即注册
查看: 970|回复: 0

[技术交流] 哪位大佬能帮我解释一下

[复制链接]
发表于 2018-5-16 16:00:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
# _*_ coding: utf-8 _*_

import csv
import re

csv_path = r"C:\Users\Dell\Desktop\项目\调试\one.csv"
save_path = r"C:\Users\Dell\Desktop\项目\调试\one.test1.csv"
readFile = open(csv_path, "r")
reader = csv.reader(readFile)
saveFile = open(save_path, 'w',newline="")
writer = csv.writer(saveFile)

leads = ['I', 'II', 'III', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'avL', 'avR', 'avF']
fileHeader = ['xml_name', 'Qdescribe'] + leads
print(fileHeader)
writer.writerow(fileHeader)

for item in reader:
    #     print(item)
    #     print(type(item))
    Qdescribe = item[1]
    label = list('000000000000')
    pattern = r'\w{2,3}\-\w{2,3}'
    match_str = re.findall(pattern, Qdescribe, re.I)#"re.I"-"使搜索对大小写不敏感"
    #     print(match_str)
    find_idx = []  # ?
    for idx, lead in enumerate(leads):
        if idx < 3:
            tmp = r'[^I]' + lead + '[^I]'  # ?
        else:
            tmp = lead
        info = re.search(tmp, Qdescribe, re.I)
        if info:
            label[idx] = '1'
        if match_str != []:
            #    if lead in match_str[0]:
            if re.search(tmp, match_str[0], re.I):
                find_idx.append(idx)
    if find_idx != []:
        #         print('find_idx',find_idx)
        try:
            label[find_idx[0]:find_idx[1] + 1] = ['1'] * len(label[find_idx[0]:find_idx[1] + 1])
        except IndexError:
            print(item[0], item[1], "list index out of range")

    writeline = item[0:2] + label
    #     print(writeline)
    writer.writerow(writeline)

readFile.close()
saveFile.close()

哪位大佬能帮我解释一下,代码里面:for idx, lead in enumerate(leads):里面,idx,lead都是什么呀,前面没有出现过呀
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-1 01:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表