[issue32078] string result of str(bytes()) in Python3
Arno-Can Uestuensoez
report at bugs.python.org
Mon Nov 20 21:54:03 EST 2017
Arno-Can Uestuensoez <acue.opensource at gmail.com> added the comment:
I got your point, missed it before, sorry.
So just for completeness.
My issue was basically about the ambiguity of the str()-constructor
and the str()-built-in-function. Therefore the len/type prints.
It works with parameters:
(3.6.2) [acue at lap001 Desktop]$ python -bb
Python 3.6.2 (default, Jul 29 2017, 14:24:56)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> str(b"abc")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
BytesWarning: str() on a bytes instance
>>>
>>>
>>> str(b"abc", "utf-8")
'abc'
>>>
>>> type(str(b"abc",'utf-8'))
<class 'str'>
>>>
Is there a common approach to force the use of the str()-constructor instead of
the str()-built-in function and/or the __str__()-method?
This would make the shared code of Python2/Python3 much easier,
at least for unicode()->str().
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32078>
_______________________________________
More information about the Python-bugs-list
mailing list