0

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

Google says it is u"\u2022", 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
Sebastian
  • 957
  • 3
  • 15
  • 27

1 Answers1

0

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

Recessive
  • 1,780
  • 2
  • 14
  • 37
  • That serves SyntaxError: Non-ASCII character '\xe2' in file script4.py on line 9, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details – Sebastian Oct 14 '18 at 03:36
  • I don't know the character number, so I can't do chr(2022). – Sebastian Oct 14 '18 at 03:37
  • I think the '\xe2' is causing a bunch of problems, in both the in built unicode decoder and imported one. Look here to fix it: https://stackoverflow.com/questions/21639275/python-syntaxerror-non-ascii-character-xe2-in-file – Recessive Oct 15 '18 at 04:37