如何将字符串转换成列表
str = '[(testing1@testing.com, amit, laspal,1,100,50),
(testing2@testing.com,None,None,None,None,None),
(testing3@testing.com,laspal, amit,None,None,None)]'
我想在列表中获取元组。 所以我的新列表将是:
list =[(testing1@testing.com, amit, laspal,1,100,50),
(testing2@testing.com,None,None,None,None,None),
(testing3@testing.com,laspal, amit,None,None,None)]
我可以使用 eval(string) 但这对我的情况不起作用。
谢谢。
请您参考如下方法:
我会说,使用正则表达式。
import re
p = re.compile('(([\w@]+),(\w+),(\w+),(\d+),(\d+))')
f = p.finditer("yourstring")
result = []
for e in f:
result.append(e.groups()[1:])
