title: How to convert an integer to a string in any base?
body: <p>Python allows easy creation of an integer from a string of a given base via </p>
  
  <pre><code>int(str, base). 
  </code></pre>
  
  <p>I want to perform the inverse: <strong>creation of a string from an integer</strong>, 
  i.e. I want some function <code>int2base(num, base)</code>, such that:</p>
  
  <pre><code>int(int2base(x, b), b) == x
  </code></pre>
  
  <p>The function name/argument order is unimportant. </p>
  
  <p>For any number <code>x</code> and base <code>b</code> that <code>int()</code> will accept.</p>
  
  <p>This is an easy function to write: in fact it's easier than describing it in this question. However, I feel like I must be missing something.  </p>
  
  <p>I know about the functions <code>bin</code>, <code>oct</code>, <code>hex</code>, but I cannot use them for a few reasons:</p>
  
  <ul>
  <li><p>Those functions are not available on older versions of Python, with which I need compatibility with (2.2) </p></li>
  <li><p>I want a general solution that can be called the same way for different bases</p></li>
  <li><p>I want to allow bases other than 2, 8, 16</p></li>
  </ul>
  
  <h3>Related</h3>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2063425/python-elegant-inverse-function-of-intstring-base">Python elegant inverse function of int(string, base)</a></li>
  <li><a href="https://stackoverflow.com/questions/2088201/integer-to-base-x-system-using-recursion-in-python">Integer to base-x system using recursion in python</a></li>
  <li><a href="https://stackoverflow.com/questions/1119722/base-62-conversion-in-python">Base 62 conversion in Python</a></li>
  <li><a href="https://stackoverflow.com/questions/561486/how-to-convert-an-integer-to-the-shortest-url-safe-string-in-python">How to convert an integer to the shortest url-safe string in Python?</a></li>
  </ul>