读取文本

def main():
    datas = []
    with open('cps_gid.txt') as f:
        for line in f:
            if line.strip('\n'): # 去空格,空行
                datas.append(line.strip('\n'))
    return datas
if __name__ == '__main__':    main()

你可能感兴趣的:(读取文本)