Creating a buffer class by extending Python str
<p>I guess this is best explained by code and comments:</p>

<pre><code>import struct

class binary_buffer(str):
    def __init__(self, msg=""):
        self = msg
    def write_ubyte(self, ubyte):
        self += struct.pack("=B", ubyte)
        return len(self)

Output
&gt;&gt; bb = binary_buffer()
&gt;&gt; bb # Buffer starts out empty, as it should
''
&gt;&gt; bb.write_ubyte(200)
1   # We can see that we've successfully written one byte to the buffer
&gt;&gt; bb
''  # Huh? We just wrote something, but where has it gone?
</code></pre>
