当前位置: 移动技术网 > IT编程>脚本编程>Python > python将每一列写入列表

python将每一列写入列表

2018年03月17日  | 移动技术网IT编程  | 我要评论

中关村美嘉,媳妇的美好时代小说,杏仁的吃法

# -*- coding: utf-8 -*-
'''
python读取文件,每一列写入一个列表
'''
def read(cor):
    data = []
    with open(cor,encoding='utf-8') as fr:
        lines = fr.readlines()
    sent_, pin_, tag_ = [], [], []
    for line in lines:
        if line != '\n':
            [char, yin, label] = line.strip().split()
            sent_.append(char)
            pin_.append(yin)
            tag_.append(label)
        elif line == '\n':
            data.append((sent_, pin_, tag_))
            sent_, pin_, tag_ = [], [], []
    print(data)
    return data
read('源文件路径')

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网