Removing control characters from a string in python -


i have following code

def removecontrolcharacters(line):     = 0     c in line:         if (c < chr(32)):             line = line[:i - 1] + line[i+1:]             += 1     return line 

this not work if there more 1 character deleted.

you use str.translate appropriate map, example this:

>>> mpa = dict.fromkeys(range(32)) >>> 'abc\02de'.translate(mpa) 'abcde' 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -