mysql 导入含逗号_将包含逗号数据的csv文件导入MySQL

首先,我假设CSV文件在字符串值周围有引号。在

因此,每个包含逗号的值都被这样的引号包围:a, b, 2, 'foo, bar'

如果是,则可以使用以下方法:

进口csv

quoteChar = "'"

myReader = csv.reader(open('largefile.csv', 'rb'), delimiter=',', quoteChar = quoteChar)

for row in myReader:

print row # this prints a list. Row is a list of values per line in your

# 'largefile.csv' file. Each row is splitted on the delimiter char.

# (comma in this case) and strings that are quoted by quoteChar (in your case

# a ' are treated differently.) This will work for your input that you've given

# in your question.

# this is what you used to do:

for line in open('largefile.csv', 'rb'):

row = line.split(quoteChar)

如果不是这样的话,那就要看你的CSV文件是什么样子了。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值