237
237
.. function:: urlencode(query[, doseq])
239
Convert a mapping object or a sequence of two-element tuples to a "url-encoded"
240
string, suitable to pass to :func:`urlopen` above as the optional *data*
241
argument. This is useful to pass a dictionary of form fields to a ``POST``
242
request. The resulting string is a series of ``key=value`` pairs separated by
243
``'&'`` characters, where both *key* and *value* are quoted using
244
:func:`quote_plus` above. If the optional parameter *doseq* is present and
245
evaluates to true, individual ``key=value`` pairs are generated for each element
246
of the sequence. When a sequence of two-element tuples is used as the *query*
247
argument, the first element of each tuple is a key and the second is a value.
248
The order of parameters in the encoded string will match the order of parameter
249
tuples in the sequence. The :mod:`urlparse` module provides the functions
239
Convert a mapping object or a sequence of two-element tuples to a
240
"url-encoded" string, suitable to pass to :func:`urlopen` above as the
241
optional *data* argument. This is useful to pass a dictionary of form
242
fields to a ``POST`` request. The resulting string is a series of
243
``key=value`` pairs separated by ``'&'`` characters, where both *key* and
244
*value* are quoted using :func:`quote_plus` above. When a sequence of
245
two-element tuples is used as the *query* argument, the first element of
246
each tuple is a key and the second is a value. The value element in itself
247
can be a sequence and in that case, if the optional parameter *doseq* is
248
evaluates to *True*, individual ``key=value`` pairs separated by ``'&'``are
249
generated for each element of the value sequence for the key. The order of
250
parameters in the encoded string will match the order of parameter tuples in
251
the sequence. The :mod:`urlparse` module provides the functions
250
252
:func:`parse_qs` and :func:`parse_qsl` which are used to parse query strings
251
253
into Python data structures.