1

I'm new to python and I'm getting this error:

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

This is my code:

# -*- coding: utf-8 -*-
hiragana_map = {"A":u"あ","I":u"い","U":u"う","E":u"え","O":u"お"}

I tried it without the u's aswell. It doesn't make a difference. I'm using the Pycharm communitiy edition. In the encoding settings it says the file is encoded with UTF-16LE.

I'd appreciate any hints.

Nopx
  • 395
  • 6
  • 12

1 Answers1

3

Python doesn't support source files encoded with with a fixed-width multi-byte codec such as UTF-16 or UTF-32.

Your file is encoded as UTF-16 Little Endian, which means the file starts with a Byte Order Mark; the first two bytes in the file are (hex) FF and FE. Python trips over the first byte.

Re-save the file as UTF-8 instead. See the PyCharm documentation, there is a section on changing the encoding.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343