我正在尝试确定在 Python中读取换行符分隔文件时处理删除换行符的最佳方法.
我想出的是以下代码,包括要测试的一次性代码.
import os def getfile(filename,results): f = open(filename) filecontents = f.readlines() for line in filecontents: foo = line.strip('\n') results.append(foo) return results blahblah = [] getfile('/tmp/foo',blahblah) for x in blahblah: print x
建议?
lines = open(filename).read().splitlines()
查看更多关于在Python中读取换行符分隔文件和丢弃换行符的最佳方法?的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did171209