A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-January/131832.html below:

[Python-Dev] PEP 461 Final?

[Python-Dev] PEP 461 Final? [Python-Dev] PEP 461 Final?Neil Schemenauer nas at arctrix.com
Sun Jan 19 02:21:25 CET 2014
Ethan Furman <ethan at stoneleaf.us> wrote:
> So, if %a is added it would act like:
>
> ---------
>    "%a" % some_obj
> ---------
>    tmp = str(some_obj)
>    res = b''
>    for ch in tmp:
>        if ord(ch) < 256:
>            res += bytes([ord(ch)]
>        else:
>            res += unicode_escape(ch)
> ---------
>
> where 'unicode_escape' would yield something like "\u0440" ?

My patch on the tracker already implements %a, it's simple.  Just
call PyObject_ASCII() (same as ascii()) then call
PyUnicode_AsLatin1String(s) to convert it to bytes and stick it in.
PyObject_ASCII does not return non-ASCII characters, no decode error
is possible.  We could call _PyUnicode_AsASCIIString(s, "strict")
instead if we are afraid for non-ASCII bytes coming out of
PyObject_ASCII.
    
  Neil

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4