string to base64 bytes, exactly with the same literal chars
<p>today I got stucked with the following issue. I can explain it better with the inverse purpose: Say we have the following base64-variable,</p>

<pre><code>b64_var = b'aGVsbG8gd29ybGQ='
</code></pre>

<p>Imagine that what we want it's not to decode it into string object of python, namely,</p>

<pre><code>base64.b64decode(b64_var).decode('utf-8')
&gt;&gt;&gt; 'hello world'
</code></pre>

<p>but the literal equivalent characters in string instead,</p>

<pre><code>repr( b64_var )[1:]
&gt;&gt;&gt; 'aGVsbG8gd29ybGQ='
</code></pre>

<p>Ok, now it's my question. I want to build a function that performs just the opposite,</p>

<pre><code>'aGVsbG8gd29ybGQ=' -&gt; b'aGVsbG8gd29ybGQ=' (base64-obj) ???
</code></pre>

<p>I got stucked, I don't know how to do it.. Any suggestion? Thank you in advance.</p>

<p>Is this doing what you want?</p>

<pre><code>b64_var = b'aGVsbG8gd29ybGQ='

print(repr(b64_var))            # b'aGVsbG8gd29ybGQ='
print(repr(b64_var)[1:])        # 'aGVsbG8gd29ybGQ='
print('b' + repr(b64_var)[1:])  # b'aGVsbG8gd29ybGQ='
</code></pre>

python string python-3.x base64 literals