python字符串转数组

import re

line = '''{name:'兰州',name:'张掖', geoCoord:[103.73, 36.03]},'''
city = re.findall("name:'(\w+)'",line)
code = re.findall("\[\d+.\d+,\s\d+.\d+\]", line)
# code = re.findall("Coord:\[(\d+.\d+),\s(\d+.\d+)\]",line)
print(city)
print(code)
print(type(code[0]))
print(eval(code[0]))
print(type(eval(code[0])))
print(tuple(eval(code[0])))
# print(tuple())
# print(tuple(map(float, code[0])))

 

你可能感兴趣的:(小技巧)