[Python-ideas] RFC: PEP 540 version 3 (Add a new UTF-8 mode)
Terry Reedy
tjreedy at udel.edu
Thu Jan 12 17:47:43 EST 2017
On 1/12/2017 12:10 PM, Victor Stinner wrote:
> Ah yes, date, thank you for the example. Here is my example using
> LC_TIME locale to format a date and LC_CTYPE to decode a byte string:
>
> date.py:
> ---
> import locale, time
> locale.setlocale(locale.LC_ALL, "")
> b = time.strftime("%a")
> encoding=locale.getpreferredencoding()
> try:
> u = b.decode(encoding)
> except UnicodeError:
> u = '<failed to decode>'
> else:
> u = repr(u)
> print("bytes: %r, text: %s, encoding: %r" % (b, u, encoding))
Since b is a string, b.decode is an AttributeError on 3.x. What am I
missing? Was this for 2.x only?
--
Terry Jan Reedy
More information about the Python-ideas
mailing list