我试图编写一个从包含包含列表的文件的“延迟”目录中读取文件的函数。下面是在延期文件夹中的文件包含:将列表从文件添加到Python中的单个列表中
'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'
用于写文件(S)的功能:
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文件的记录合并。
这功课吗? – 2009-11-30 15:10:09