Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从二进制文件中提取纯文本_Python_File_Binary - Fatal编程技术网

Python 从二进制文件中提取纯文本

Python 从二进制文件中提取纯文本,python,file,binary,Python,File,Binary,我发现了一个对我来说非常重要的二进制文件。 如果我在文本编辑器中打开它,我会看到很多二进制数据,但有些字符串是纯文本 我用python阅读我的文件 with open(my_precious_file, mode='rb') as file: # b is important -> binary fileContent = file.read() fileContent包含大量没有ascii对应字符的二进制值/x00,以及我的字符串 如何清理它,即返回一个只包含可打印字符的字符串

我发现了一个对我来说非常重要的二进制文件。 如果我在文本编辑器中打开它,我会看到很多二进制数据,但有些字符串是纯文本

我用python阅读我的文件

with open(my_precious_file, mode='rb') as file: # b is important -> binary
    fileContent = file.read()
fileContent包含大量没有ascii对应字符的二进制值
/x00
,以及我的字符串


如何清理它,即返回一个只包含可打印字符的字符串?

您可以尝试使用

例:


为什么不按照文件的实际类型正确对待它呢?自定义的,未记录的,遗留的,未知的文件格式如果它是未记录的,你怎么知道它是自定义的?我希望我能告诉你。这是我掌握的唯一信息
import io
with io.open(filename,'rb',encoding='utf8') as f:
    fileContent = file.read()