handling of non-ASCII filenames?
Ulli Horlacher
framstag at rus.uni-stuttgart.de
Thu Nov 19 02:54:28 EST 2015
Christian Gollwitzer <auriocus at 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: horlacher at 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/
More information about the Python-list
mailing list