Python 3.x and bytes

Felipe Bastos Nunes felipe.bastosn at gmail.com
Tue May 17 15:22:30 EDT 2011


They accept .replace(b"00", b"12") for example. Documentation about
it.<http://docs.python.org/py3k/library/stdtypes.html#bytes-methods>

2011/5/17 Ethan Furman <ethan at stoneleaf.us>

> In Python 3 one can say
>
> --> huh = bytes(5)
>
> Since the bytes type is actually a list of integers, I would have expected
> this to have huh being a bytestring with one element -- the integer 5.
>  Actually, what you get is:
>
> --> huh
> b'\x00\x00\x00\x00\x00'
>
> or five null bytes.  Note that this is an immutable type, so you cannot go
> in later and say
>
> --> huh[3] = 9
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: 'bytes' object does not support item assignment
>
>
> So, out of curiosity, does anyone actually use this, um, feature?
>
> ~Ethan~
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Felipe Bastos Nunes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110517/0d90b7f7/attachment.html>


More information about the Python-list mailing list