简体   繁体   中英

How do you identify the unicode value for a character?

I'm trying to replace this value from my text file

Google says it is u"\•", but when I do this nothing prints

from unidecode import unidecode

text = open('file.txt','r+')

l=[]

for i in text.readlines():
    if  unidecode(u"\u2022") in i:
        print "confirmed %r" % i

It prints out the lines if I go into the file and replace the values with an asterisk.

I tried putting the character into its own file

from unidecode import unidecode

import unicodedata

text = open('unicode_char.txt','r+')

for i in text:
    print unidecode(i)

That serves UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

Edit -

I figured it out.

point = unichr(8226)
encoded = point.encode('utf-8')

for i in text.readlines():
     if encoded in i:
         print i

If you're looking for a specific character, you could try just copying and pasting it directly into the code, ie,

if 'ߦ' in i:
...

but some of those can be a pain to get, so try this:

if chr(2022) in i:
...

Sorry if I misunderstood the question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM