这是解析字符串并检索参数及其值的基本 Python 脚本。
import re
link = "met_y=population&fdim_y=patientStatus:7&fdim_y=pregnant:1&scale_y=lin&ind_y=false&rdim=department&idim=department:9:2:4&idim=clinic:93301:91100:93401:41201:41100&ifdim=department&tstart=1190617200000&tend=1220511600000&ind=false&draft"
print link
filters = ''
matches = re.findall("\&?(?P<name>\w+)=(?P<value>(\w|:)+)\&?",link )
for match in matches:
name = match[0]
value = match[1]
selection = value.split(':')
filters = {}
print selection[0]
print selection[1:len(selection)]
filters[selection[0]] = selection[1:len(selection)]
print filters
这里的问题是哈希表过滤器永远不会获取这些值。这个脚本的输出是
{'false': []}
我究竟做错了什么?