将.txt文件的内容读入python中的列

时间:2016-03-09 07:53:54

标签: python-3.x two-columns

我有一个文本文件,其中包含以下列格式存储的客户名称和ID号:

名称

身份证号码

名称

身份证号码

名称

身份证号码......

在python中是否有办法读取文件的内容并输出为2列,如下所示:

名称IDNumber

1 个答案:

答案 0 :(得分:0)

def col():
    sample= open("members.txt","r")
    found=sample.read().splitlines()
    Name=found[::2]
    ID=found[1::2]
    for c1, c2 in zip(Name, ID):
        print (("%-9s %s") % (c1, c2))
相关问题