str(bytes) in Python 3.0

Christian Heimes lists at cheimes.de
Sat Apr 12 11:13:51 EDT 2008


John J. Lee schrieb:
> Why hasn't the one-argument str(bytes_obj) been designed to raise an
> exception in Python 3?

See for yourself:

$ ./python
Python 3.0a4+ (py3k:0, Apr 11 2008, 15:31:31)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> str(b'')
"b''"
[38544 refs]
>>> bytes("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string argument without an encoding
[38585 refs]

$ ./python -b
Python 3.0a4+ (py3k:0, Apr 11 2008, 15:31:31)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> str(b'')
__main__:1: BytesWarning: str() on a bytes instance
"b''"
[38649 refs]

Christian




More information about the Python-list mailing list