result = [] for k, vs in to_key_val_list(data): if isinstance(vs, basestring) or not hasattr(vs, '__iter__'): vs = [vs] for v in vs: if v is not None: result.append( (k.encode('utf-8') if isinstance(k, str) else k, v.encode('utf-8') if isinstance(v, str) else v)) return urlencode(result, doseq=True)
result 在这里还是个list, 不用担心重复问题, 那么问题就一定是在for k, vs in to_key_val_list(data)了, to_key_val_list是utils.py里的一个函数, 简单粗暴
def items(self, multi=False): """Return an iterator of ``(key, value)`` pairs. :param multi: If set to `True` the iterator returned will have a pair for each value of each key. Otherwise it will only contain pairs for the first value of each key. """
for key, values in iteritems(dict, self): if multi: for value in values: yield key, value else: yield key, values[0]
for row in tables[0].rows: row_temp = [] for cell in row.cells: if cell.text != null_text: row_temp.append(cell.text) cell.text = null_text table_temp.append(row_temp) table_temp