您已将行分为几列:
parts = (line.split(',') for line in f)
然后尝试剥离每个列列表:
column = (part.strip() for part in parts)
那行不通。去除每一列:
column = ([col.strip() for col in part] for part in parts)
但是,您可能想使用该
csv模块来完成从文件到数据行的转换:
with open("/home/mic/tmp/test.txt", 'rb') as f: reader = csv.reader(f, skipinitialspace=True) for object_ in iter_something(reader): print(object_)
该
skipinitialspace选项确保删除定界符后紧跟的空格。当然,每行末尾的换行符也会被删除。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)