How to add abilities to strings in Python
<p>This is more of a curiosity question than anything else. I'm new with Python and playing around with it. I've just looked at the base64 module. What if instead of doing:</p>

<pre><code>import base64
string = 'Foo Bar'
encoded = base664.b64encode
</code></pre>

<p>I wanted to do something like:</p>

<pre><code>&gt;&gt;&gt; class b64string():
&gt;&gt;&gt;   &lt;something&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; string = b64string('Foo Bar')
&gt;&gt;&gt; string
'Foo Bar'
&gt;&gt;&gt; string.encode64()
'Rm9vIEJhcg=='
&gt;&gt;&gt; string
'Rm9vIEJhcg=='
&gt;&gt;&gt; string.assign('QmFyIEZvbw==')
&gt;&gt;&gt; string
'QmFyIEZvbw=='
&gt;&gt;&gt; string.b64decode()
'Bar Foo'
&gt;&gt;&gt; string
'Bar Foo'
</code></pre>

<p>Is there a simple, pythonic way to create that class?</p>

<p>I've begun with this:</p>

<pre><code>&gt;&gt;&gt; class b64string(base64):
...   def __init__(self, v):
...     self.value=v
</code></pre>

<p>And already I get:</p>

<pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: Error when calling the metaclass bases
    module.__init__() takes at most 2 arguments (3 given)
</code></pre>

<p>And don't get me started on (just to see what would happen):</p>

<pre><code>&gt;&gt;&gt; class b64string(str, base64): pass
... 
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: Error when calling the metaclass bases
    metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
</code></pre>

<p>I know how to do it manually by listing all of the attributes of base64 in a new class and calling them with the stored value as argument. But is there a neat, pythonic way to do this? Is it a bad idea to do it? The idea would be, if needed, to do it with many such modules and have "super strings" that would have as modules all the things I would need to do with them. Is that bad? Is it un-pythonic? If it is pythonic, how is it done?</p>
