如何分开&使用Python将字符串存储到CSV行的变量中?

时间:2017-03-09 01:12:05

标签: python string csv

如何从CSV行中分离和存储字符串,例如;

我有这个字符串:

data = "product name, description, weight, shipping dest"

我想保存到这样的python变量中:

a = "product name"
b = "description"
c = "weight"
d = "shipping dest"

提前致谢!

1 个答案:

答案 0 :(得分:1)

使用字符串的分割功能:

data = "product name, description, weight, shipping dest"
a, b, c, d = data.split(', ')

以下是Python 2.7的参考资料:https://docs.python.org/2/library/stdtypes.html#str.split

这是Python 3的参考: https://docs.python.org/3.5/library/stdtypes.html#str.split