Christian Gollwitzer <aurio...@gmx.de> wrote: > Am 18.11.15 um 17:45 schrieb Ulli Horlacher: > > This is my encoding function: > > > > def url_encode(s): > > u = '' > > for c in list(s): > > if match(r'[_=:,;<>()+.\w\-]',c): > > u += c > > else: > > u += '%' + c.encode("hex").upper() > > return u > > > > > > The quoting is applied to a UTF8 string.
encode("hex") works only with binary strings? How do I convert a UTF8 string to binary? > But I think you shouldn't do it yourself, use a library function: > > import urllib > urllib.quote(yourstring.encode('utf8')) It does not encode exactly the same way I need it. Besides this, I want to understand how Python handles strings and character encoding. -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de Universitaet Stuttgart Tel: ++49-711-68565868 Allmandring 30a Fax: ++49-711-682357 70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ -- https://mail.python.org/mailman/listinfo/python-list