gnuos
4/27/2017 - 4:49 AM

select_text_field.py

# -*- coding:utf-8 -*-
'''
Author: Kevin
'''


def get_column(file, col):
    '''
    按照Tab制表符分割文件的列,并按照参数返回指定的列的List
    参数:
        f, 文件
        c, 列数
    '''
    field = []
    with open(file, 'r') as src:
        for line in src:
            if line == "\n":
                continue
            row = line.strip().split(',')
            field.append(row[col])
    return field

print(get_column('demo.txt', 2))