2008年1月25日 星期五

如何利用Python處理檔案

如何利用python讀取檔案的第四條line
檔案不用整個load到記憶體上

how-to get a specific line(4) in a bunch of files without it going loading into memory

import glob
for files in glob.glob('/home/joec/Desktop/gpr_files/*gpr'):
x = open(files)
x.readline()
x.readline()
x.readline()
y = x.readline()
z = y[10:20]
date = z.replace('/', '-')
print date
x.close()

http://groups.google.com/group/comp.lang.python/browse_thread/thread/7f3f745dd4e09f5e/f2934e1a17ee66a3

沒有留言: