【发布时间】:2009-11-30 15:05:26
【问题描述】:
我正在尝试编写一个函数,该函数从“延迟”目录中读取文件,该目录包含包含列表的文件。以下是 deferred 文件夹中的文件包含的内容:
'173378981', '45000', '343434', '3453453', '34534545', '3452342', '234234', '42063008', 'Exempted', '10000'
'1000014833', '0', '0', '0', '0', '0', '0', '0', 'Exempted', '0'
'1000009598', '0', '0', '0', '0', '0', '0', '0', 'Exempted', '0'
'279483421', '0', '0', '0', '0', '0', '0', '0', 'Exempted', '0'
'1000009600', '0', '0', '0', '0', '0', '0', '0', 'Exempted', '0'
'389453080', '0', '0', '0', '0', '0', '0', '0', 'Exempted', '0'
'1000009602', '0', '0', '0', '0', '0', '0', '0', 'Exempted', '0'
用于写入文件的函数:
def storeDeferredRecords(records):
"""docstring for createFile"""
now = datetime.datetime.now()
filename = deferredDir + '/' + now.strftime("%Y%m%d-%H%M%S")
f = open(filename, 'w')
newlist = map(lambda(x): str(x)[1:-1], records)
for item in newlist:
f.write("%s\n" % item)
f.close
我需要有关用于读取文件的函数的帮助。我只能这样写:
def getDeferredRecords():
"""docstring for getDeferredRecords"""
infiles = [infile for infile in glob.glob(deferredDir + '/*')]
<code to read the contents of each file here>
有人可以帮帮我吗?我需要阅读这些行并将它们插入到列表中。然后,此列表将与来自单独 CSV 文件的记录合并。
【问题讨论】: