python - 什么编码看起来完全像 ASCII 但每个字节前都有 NULL 字节?

标签 python character-encoding

我有一个字符串,其外观和行为如下(提供的 Python 代码)。卧槽?!它采用什么编码?

s = u'\x00Q\x00u\x00i\x00c\x00k'
>>> print s
Quick
>>>
>>> s == 'Quick'
False
>>>
>>> import re
>>> re.search('Quick', s)
>>>
>>> import chardet
>>> chardet.detect(s)
/usr/lib/pymodules/python2.6/chardet/universaldetector.py:69: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if aBuf[:3] == '\xEF\xBB\xBF':
/usr/lib/pymodules/python2.6/chardet/universaldetector.py:72: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif aBuf[:4] == '\xFF\xFE\x00\x00':
/usr/lib/pymodules/python2.6/chardet/universaldetector.py:75: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif aBuf[:4] == '\x00\x00\xFE\xFF':
/usr/lib/pymodules/python2.6/chardet/universaldetector.py:78: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif aBuf[:4] == '\xFE\xFF\x00\x00':
/usr/lib/pymodules/python2.6/chardet/universaldetector.py:81: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif aBuf[:4] == '\x00\x00\xFF\xFE':
/usr/lib/pymodules/python2.6/chardet/universaldetector.py:84: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif aBuf[:2] == '\xFF\xFE':
/usr/lib/pymodules/python2.6/chardet/universaldetector.py:87: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif aBuf[:2] == '\xFE\xFF':
{'confidence': 1.0, 'encoding': 'ascii'}
>>>
>>> chardet.detect(s)
{'confidence': 1.0, 'encoding': 'ascii'}
>>> 

最佳答案

UTF-16 大端

关于python - 什么编码看起来完全像 ASCII 但每个字节前都有 NULL 字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3759189/

相关文章:

python - 如何解决 numpy 中的内存 View 错误?

python - 如何在 bottle 中使用 jinja2 i18n(带 babel)

windows - 检测 C/C++ 中字符串的编码

xml - Flash 中 xml 文件中的特殊字符未显示

javascript - 从 asp.net 3.5 升级到 asp.net 4.0 会导致某些回发出现 javascript 错误

java - 从代码页 1252 的 FileItem 读取包括欧元符号的内容

python - “self”未定义 - 使用计时器进行线程处理

python - 如何将列表拆分为更小的列表?

python - 奇怪的 PYTHONPATH 问题

character-encoding - 序言中是否有字母字符检查?