Sanjit Sarda
Sanjit Sarda

Reputation: 391

How do you represent this character in python? 

The empty box character shows up in a text, in place of a non-ascii character, so I need to replace that character in python, but I get an error:

SyntaxError: Non-ASCII character '\xef' in file pyautoGuiTiReg/main.py on line 197, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details.

I am not sure what encoding to use as this is a very weird symbol:

Upvotes: 1

Views: 109

Answers (2)

Nikolai Kamenskiy
Nikolai Kamenskiy

Reputation: 139

For replace it try this

ToBytes = str.encode('yourString', encoding='utf-8')     
ReplaceBytes = ToBytes.replace(b'\xef',b'').decode('utf-8')

Upvotes: 1

Sanjit Sarda
Sanjit Sarda

Reputation: 391

As @AnshumanTiwari mentioned in the comments, utf-8 is the way to go when in doubt. By adding # -*- coding: utf-8 -*- to the top of the code, it ends up working perfectly.

Upvotes: 1

Related Questions