Convert string to char array

Larry Bates larry.bates at`
Tue Jul 1 20:57:16 CEST 2008

Brandon wrote:
> How do I convert a string to a char array?  I am doing this so I can edit 
> the string received from an sql query so I can remove unnecessary 
> characters. 
The precise answer is:

 >>> s = 'abcdefghi'
 >>> l = list(s)
 >>> l
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']

But quite often you can just to the replace without doing the conversion

 >>> s = 'abc,de,fghi'
 >>> s2 = s.replace(',','')
 >>> s2 = s.replace(',','')


More information about the Python-list mailing list