How do you retain query parameter order and explicitly blank values?
parse_qsl returns key–value pairs in encounter order. keep_blank_values retains fields with an empty value.
Python example and interpretation
A first tag, blank note and second tag all survive as pairs. Converting them to a plain dictionary would overwrite the first tag and change a replay.
from urllib.parse import parse_qsl
parse_qsl('tag=A¬e=&tag=B',keep_blank_values=True)Result [('tag', 'A'), ('note', ''), ('tag', 'B')]
中文
怎样保留查询参数出现的次序和显式空值?
parse_qsl 按出现顺序返回键值对列表,keep_blank_values 可保留值为空的字段。
Python 算例与适用条件
tag=A、空的 note、tag=B 可同时保留。直接转为字典会让后一个 tag 覆盖前一个,影响请求回放。
from urllib.parse import parse_qsl
parse_qsl('tag=A¬e=&tag=B',keep_blank_values=True)结果 [('tag', 'A'), ('note', ''), ('tag', 'B')]