python - Remove special character -


how convert input text 'abcde'f gh'to output 'abcdefgh'?

this did not work.

a='abcde'f gh' b=a.translate({(u"\u0027"):none}) 

you should escape apostrophe ' or use quotes " define string:

>> a='abcde\'f gh' 

or

>> a="abcde'f gh" 

to remove symbol ' , spaces, use string.translate this:

>> b = a.translate(none," \'") 'abcdefgh' 

string.translate(s, table[, deletechars])

delete characters s in deletechars (if present), , translate characters using table, must 256-character string giving translation each character value, indexed ordinal. if table none, character deletion step performed.


Popular posts from this blog