csv读取
# -*- coding: utf-8 -*-
import os
import sys
import string
newline, s = ("", "")
try:
f = open(u"简易记账.csv")
except IOError:
print "文件不存在!".decode('utf8').encode('gbk')
sys.exit()
f1 = open(u"结果.txt", 'w')
total, n = (0, 1)
for line in f:
if n == 1:
n += 1
continue
mylist = line.decode('utf8').encode('gbk').split(',')
del mylist[0:4]
del mylist[2]
date = mylist[0][0:10]
date = date.replace('-', '')
money = float(mylist[1])
total += money
s = '{0} {1:>3.0f} {2}'.format(date, money, mylist[2])
newline += s
newline += '{0:>8s} {1:>3.0f}'.format("合计:".decode('utf8').encode('gbk'), total)
f1.write(newline)
f1.close()
f.close()
raw_input("请按任意键继续!".decode('utf8').encode('gbk'))
每次都要解码