python - Reading all kinds of files in different encodings

不羁岁月 提交于 2019-12-06 07:27:54

Change your view. You don't "hide UTF-8 text in images". You hide bytes in images.

These bytes could be - purely accidentally - interpretable as UTF-8-encoded text. But in reality they could be anything.

Reading a file as text with open("...", encoding="...") has the hidden step of decoding the bytes of the file into string. This is convenient when you want to treat the file contents as string in your program.

Skip that hidden decoding step and read the file as bytes: open("...", "rb").

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