Lexical error: Encountered: “” (0), after : “”

泄露秘密 提交于 2019-12-02 00:29:48

问题


I needed to start dealing with foreign characters, and in doing so, I think I royally screwed up a file's encoding.

The error I'm getting is:

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

The first line of the file is:

import xml.etree.cElementTree as ET

Also of note: when I pasted the line above into the textarea to ask this question, and submitted, an unknown character appeared between every character (e I have been unable to fix this issue by adding an explicit coding definition:

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

I have also been unable to revert the file (using Hg) to a previous version, nor copy/paste code into a new file, or replace the broken file with copied/pasted code.

Please help!


回答1:


If it is indeed a zero character in there, you may find you've injected some UTF-16/UCS-2 text. That particular Unicode encoding would have a zero byte in between every ASCII character.

The best way to find out is to do a hex dump of you file with something like od -xcb myfile.py.

If that is the case, then you'll need to edit the file with something that's able to see those characters, and fix them up.

vi would be my first choice (since that's what I'm used to) but I don't want to start any holy wars with the Emacs illuminati. In vi, they'll most likely show up as ^@ characters.



来源:https://stackoverflow.com/questions/6501115/lexical-error-encountered-0-after

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!