On 11/8/21 4:45 AM, Victor Stinner wrote: > Is it implement "like" ascii(obj).encode("ascii") but with minor > changes? What changes?
It works like `str()`, but you get ascii-encoded bytes (or an exception if that's not possible). The difference with the built-in ascii is the absence of extra quotes and the `b` indicator when a string is used: ``` >>> u_var = u'abc' >>> b_var = b'abc' >>> str(u_var) 'abc' >>> str(b_var) "b'abc'" >>> ascii(b_var) "b'abc'" >>> b'%a' % (u_var) # the docs will be updated to refer to %a as "ascii-repr" b"'abc'" # as it mirrors %r but only returns ascii-encoded bytes >>> bytes.ascii(u_var) b'abc' -- ~Ethan~ _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/X3XUYTCEM7IWTID2GING62LCEG3XKM7Q/ Code of Conduct: http://python.org/psf/codeofconduct/