How do I convert a list of ascii values to a string in python?

Electrons_Ahoy picture Electrons_Ahoy · Oct 7, 2008 · Viewed 164.9k times · Source

I've got a list in a Python program that contains a series of numbers, which are themselves ASCII values. How do I convert this into a "regular" string that I can echo to the screen?

Answer

Thomas Wouters picture Thomas Wouters · Oct 7, 2008

You are probably looking for 'chr()':

>>> L = [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]
>>> ''.join(chr(i) for i in L)
'hello, world'