我能做些什么来优化这个功能,让它看起来更像pythonic?
def flatten_rows_to_file(filename, rows):
f = open(filename, 'a+')
temp_ls = list()
for i, row in enumerate(rows):
temp_ls.append("%(id)s\t%(price)s\t%(site_id)s\t%(rating)s\t%(shop_id)s\n" % row)
if i and i % 100000 == 0:
f.writelines(temp_ls)
temp_ls = []
f.writelines(temp_ls)
f.close()