词法错误:遇到:“" (0),在:“"之后. [英] Lexical error: Encountered: "" (0), after : ""
问题描述
我需要开始处理外来字符,在这种情况下,我认为我很容易弄乱文件的编码.
I needed to start dealing with foreign characters, and in doing so, I think I royally screwed up a file's encoding.
我得到的错误是:
Lexical error at line 1, column 8. Encountered: "" (0), after : ""
文件的第一行是:
import xml.etree.cElementTree as ET
还要注意:当我将上面的行粘贴到textarea中问这个问题并提交时,每个字符之间都出现了一个未知字符(例如 我无法通过添加明确的编码定义来解决此问题:
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 -*-
我也无法将文件(使用Hg)还原到以前的版本,也无法将代码复制/粘贴到新文件中,也无法用复制/粘贴的代码替换损坏的文件.
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.
请帮助!
推荐答案
如果其中确实是零字符,则可能会发现您注入了一些UTF-16/UCS-2文本.特定的Unicode编码在每个ASCII字符之间都有一个零字节.
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.
找出答案的最佳方法是使用od -xcb myfile.py
之类的文件对文件进行十六进制转储.
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
是我的第一选择(因为这是我的习惯),但是我不想与Emacs illuminati展开任何圣战.在vi
中,它们很可能会显示为^@
字符.
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.
这篇关于词法错误:遇到:“" (0),在:“"之后.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!