title: Python elegant inverse function of int(string,base)
body: <p>Python allows conversions from string to integer using any base in the range [2,36] using:</p>
  <pre><code>int(string,base)
  </code></pre>
  <p>I am looking for an elegant inverse function that takes an integer and a base and returns a string.</p>
  <p>For example:</p>
  <pre><code>&gt;&gt;&gt; str_base(224,15)
  'ee'
  </code></pre>
  <p>I came up with the following solution:</p>
  <pre><code>def digit_to_char(digit):
      if digit &lt; 10: return chr(ord('0') + digit)
      else: return chr(ord('a') + digit - 10)
  
  def str_base(number,base):
      if number &lt; 0:
          return '-' + str_base(-number,base)
      else:
          (d,m) = divmod(number,base)
          if d:
              return str_base(d,base) + digit_to_char(m)
          else:
              return digit_to_char(m)
  </code></pre>
  <p>Note: <code>digit_to_char()</code> works for bases &lt;= 169 arbitrarily using ASCII characters after <code>z</code> as digits for bases above 36.</p>
  <p>Is there a Python built‑in, library function, or a more elegant inverse function of <code>int(string,base)</code>?</p>