title: Encoding a string to base64 in Python 2.x vs Python 3.x
body: <p>In Python 2, I used to could do this:</p>
  
  <pre><code>&gt;&gt;&gt; var='this is a simple string'
  &gt;&gt;&gt; var.encode('base64')
  'dGhpcyBpcyBhIHNpbXBsZSBzdHJpbmc=\n'
  </code></pre>
  
  <p>Easy!  Unfortunately, this don't work in Python 3.  Luckily, I was able to find an alternative way of accomplishing the same thing in Python 3:</p>
  
  <pre><code>&gt;&gt;&gt; var='this is a simple string'
  &gt;&gt;&gt; import base64
  &gt;&gt;&gt; base64.b64encode(var.encode()).decode()
  'dGhpcyBpcyBhIHNpbXBsZSBzdHJpbmc='
  </code></pre>
  
  <p>But that's terrible!  There has to be a better way!  So, I did some digging and found a second, alternative method of accomplishing what used to be a super simple task:</p>
  
  <pre><code>&gt;&gt;&gt; var='this is a simple string'
  &gt;&gt;&gt; import codecs
  &gt;&gt;&gt; codecs.encode(var.encode(),"base64_codec").decode()
  'dGhpcyBpcyBhIHNpbXBsZSBzdHJpbmc=\n'
  </code></pre>
  
  <p>That's even worse! I don't care about the trailing newline! What I care about is, jeez, there's <em>gotta</em> to be a better way to do this in Python 3, right?</p>
  
  <p>I'm not asking "why".  I'm asking if there is a better way to handle this simple case.</p>