Why don’t python integers have a smart toString method like java/javascript? It’s easy to convert strings into numbers using int(str_whatever) or float(str_whatever) but to convert them back you have only the decimal system (using str(number) or “%d” % number). In case you want to convert to binary, base32, base36, base64, you’re gonna have to write your own conversion function. Batteries included?
Use either:
http://pastebin.com/f54dd69d6
http://code.activestate.com/recipes/65212/
http://code.activestate.com/recipes/111286/
I added a feature request, lets see if it gets completely shot down:
The more common ones exist %x, %o. In newer pythons, %b for binaries as well. Bases like 32, 64 are a bit less useful… (unless you mean base64 encoding, which is something else entirely)
I do mean bases like 32, 36, 62, 64 and user defined bases. Here’s a use case for representing numbers in different bases – shortening a number for exposing url’s on a website, like video id’s on youtube.