3
這是一個基本的python腳本,用於分析字符串並檢索參數及其值。Python Hashtable不會保存我傳給它的列表片段
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': []}
我在做什麼錯?
謝謝!它做了詭計。我應該花更多時間調試它,但一直認爲這是列表複製的一個問題(http://henry.precheur.org/python/copy_list)。 – Asimov4