This piece of code works fine for me:<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote"><div style="margin-left: 40px;">>>> somevar = bytes()<br>
>>> somevar<br>''<br>>>> somevar.replace(b'', b'10')<br>'10'<br>>>> somevar<br>''<br>>>> somevar = somevar.replace(b'', b'10')<br>
>>> somevar<br>'10'<br>>>> somevar2 = bytes(b'10'*2)<br>>>> somevar2<br>'1010'<br>>>> somevar2 = somevar2.replace(b'01', b'57'*3)<br>>>> somevar2<br>
'15757570'<br><br></div></blockquote>They're unmutable, but replace deals with it.<br><div class="gmail_quote">2011/5/17 Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Felipe Bastos Nunes wrote:<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2011/5/17 Ethan Furman wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
In Python 3 one can say<br>
<br>
--> huh = bytes(5)<br>
<br>
Since the bytes type is actually a list of integers, I would have<br>
expected this to have huh being a bytestring with one element -- the<br>
integer 5. Actually, what you get is:<br>
<br>
--> huh<br>
b'\x00\x00\x00\x00\x00'<br>
<br>
or five null bytes. Note that this is an immutable type, so you<br>
cannot go in later and say<br>
<br>
--> huh[3] = 9<br>
Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>
TypeError: 'bytes' object does not support item assignment<br>
<br>
<br>
So, out of curiosity, does anyone actually use this, um, feature?<br>
</blockquote></blockquote>
><br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
They accept .replace(b"00", b"12") for example.<br>
</blockquote>
<br>
So they do. Although that particular example doesn't work since b'0' is the integer 48...<br>
<br>
--> huh.replace(b'00',b'12')<div class="im"><br>
b'\x00\x00\x00\x00\x00'<br>
<br>
<br></div>
The big question, though, is would you do it this way:<br>
<br>
some_var = bytes(23).replace(b'\x00', b'a')<br>
<br>
or this way?<br>
<br>
some_var = bytes(b'a' * 23)<br><font color="#888888">
<br>
~Ethan~<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Felipe Bastos Nunes<br>