我試圖編寫一個從包含包含列表的文件的「延遲」目錄中讀取文件的函數。下面是在延期文件夾中的文件包含:將列表從文件添加到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