如何从CSV行中分离和存储字符串,例如;
我有这个字符串:
data = "product name, description, weight, shipping dest"
我想保存到这样的python变量中:
a = "product name"
b = "description"
c = "weight"
d = "shipping dest"
提前致谢!
答案 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