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

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

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