Error: Non-ASCII character '\xe2' in file

Asked 2 years ago, Updated 2 years ago, 177 views

Error: How do I resolve the Non-ASCII character '\xe2' in file?

It doesn't pop up when I use English, but it only pops up when there is Korean

$ cat bla.py 
print "Hi!"
$ $ python bla.py

File "bla.py", line 1 SyntaxError: Non-ASCII character '\xe2' in file bla.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

python encoding utf-8 character-encoding

2022-09-22 10:36

1 Answers

If you look at PEP 0263,

#!/usr/bin/env python
# # -*- coding: utf-8 -*-

Please add something to the top. Then you can write UTF-8 to the string.

$ cat mine.py
#!/usr/bin/env python
# # -*- coding: utf-8 -*-
print "Hi!"

$ $ python mine.py 
Good-bye!


2022-09-22 10:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.