python csv用法_关于python-csv的使用介绍

打开csv

a1555f364f59a0935ae25212a27f7361.png

56b608ded653a123816ec3cdd87de3ca.png

# -*- coding: utf8 -*-import csv

with open('test.csv','rb') as my:

lines=csv.reader(my)

for line in lines:

print line

# -*- coding: utf8 -*-import csv

with open('text01.csv','wb') as my:

mywriter=csv.writer(my)

mywriter.writerow([1,'a'])

mywriter.writerow([2,'b'])

lists=[[3,5],[4,6]]

mywriter.writerows(lists)

b2ac1dc670f29300ab1cac65e4c7a1ba.png

# -*- coding: utf8 -*-import csv

with open('text01.csv','rb') as my:

lines=csv.reader(my,csv.register_dialect('mydialect',delimiter='|', quoting=csv.QUOTE_ALL))

print lines.line_num

for line in lines:

print line

b817d1ebf7624a81377dba9d85afcaeb.png

# -*- coding: utf8 -*-import csv

with open('text.csv', 'wb') as csvfile:

spamwriter = csv.writer(csvfile, delimiter=' ',

quotechar='|', quoting=csv.QUOTE_MINIMAL)

spamwriter.writerow(['tiger'] * 5 + ['pig '])

spamwriter.writerow(['cat', 'mouse', 'dog'])

4ee88b7d419e5d6e7c0ba76d0e0ad0e7.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值