[Python-Dev] [Python-checkins] cpython: Issue #11049: adding some tests to test.support

Antoine Pitrou solipsis at pitrou.net
Wed Jul 27 15:44:07 CEST 2011


On 2011年7月27日 16:31:54 +0300
Eli Bendersky <eliben at gmail.com> wrote:
>> I wasn't aware of '%a' at all? It doesn't appear to be documented, and
> Python 2.6 doesn't support it:
>> ValueError: unsupported format character 'a' (0x61) at index 1
>> If it's new, it should at least be documented in library/stdtypes with the
> other formatting operations.

It's new in 3.x and maps to the ascii() builtin:
>>> ascii('hé')
"'h\\xe9'"
>>> '%a' % 'hé'
"'h\\xe9'"
The docstring for ascii():
 ascii(object) -> string
 
 As repr(), return a string containing a printable representation of
 an object, but escape the non-ASCII characters in the string
 returned by repr() using \x, \u or \U escapes. This generates a
 string similar to that returned by repr() in Python 2.
Regards
Antoine.


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /