How can I replace a character in a string with a non ascii character in python?

I want to replace the number sign (#) with a character like a sign called the musical sharpness sign (β™―). I tried the following line but didn't work.

res['n'].replace('#', 'β™―')

      

I also tried them and also didn't work fine.

res['n'].replace('#', u'β™―')
res['n'].replace('#', '\xe2')

      

Anyone got an idea of ​​the situation?

+3


source to share


3 answers


res="He##o"
res=res.replace("#","β™―")
print res

o/t Heβ™―β™―o

      



+2


source


import re
text = ' '
re.sub(' ', '\x00', text)

      



Why don't you use this?

0


source


Replace returns the modified string, the strings cannot be modified by themselves. Try

res['n'] = res['n'].replace('#', 'β™―')

      

0


source







All Articles