Lexical error: Found: "(0), after:" "

I needed to start communicating with foreign characters, and by doing this, I think that I have ruined the encoding of the file royally.

The error I am getting is:

Lexical error at line 1, column 8. Encountered: "" (0), after : "" 

The first line of the file:

 import xml.etree.cElementTree as ET 

Also note: when I inserted the line above in the text box to ask this question and presented, an unknown character appeared between each character (e I could not fix this problem by adding an explicit encoding definition:

 # -*- coding: utf-8 -*- 

I also failed to return the file (using Hg) to the previous version, and also did not copy / paste the code into a new file or replace the broken file with the copied / pasted code.

Please, help!

+3
source share
1 answer

If this is really a null character, you may find that you entered the text UTF-16 / UCS-2. This particular Unicode encoding will have a zero byte between all ASCII characters.

The best way to find out is to hex dump your file with something like od -xcb myfile.py .

If so, you will need to edit the file with something that can see these characters and fix them.

vi would be my first choice (since I'm used to it), but I don't want to start holy wars with the Illuminati Emacs. In vi they will most likely display as ^@ characters.

+3
source

Source: https://habr.com/ru/post/1273791/


All Articles