Convert int to ASCII and back in Python


I'm working on making a URL shortener for my site, and my current plan (I'm open to suggestions) is to use a node ID to generate the shortened URL. So, in theory, node 26 might be, node 1 might be, node 52 might be, and node 104 might be When a user goes to that URL, I need to reverse the process (obviously).

I can think of some kludgy ways to go about this, but I'm guessing there are better ones. Any suggestions?

1/26/2016 5:42:41 PM

ASCII to int:


gives 97

And back to a string:

  • in Python2: str(unichr(97))
  • in Python3: str(chr(97))

gives 'a'

11/26/2018 11:33:17 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow