Python中文
首页
教程
问答
标签
搜索
登录
注册
用python对大文件执行xoring
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图对一些文件应用xOr操作,其中一些文件非常大。 <br/>基本上我得到了一个文件,并逐字节对其进行异或(或者至少我认为我正在这样做)。当它碰到一个更大的文件(大约70MB)时,我得到一个内存不足的错误,我的脚本崩溃。 <br/>我的电脑有16GB的Ram,其中50%以上可用,因此我不会将其与硬件联系起来。在</p> <pre><code>def xor3(source_file, target_file): b = bytearray(open(source_file, 'rb').read()) for i in range(len(b)): b[i] ^= 0x71 open(target_file, 'wb').write(b) </code></pre> <p>我试图分块读取文件,但似乎我太没经验了,因为输出不是所需的。当然,第一个函数返回我想要的:) <br/></p> ^{pr2}$ <p><br/>这种手术的合适解决方案是什么?我做错什么了?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>除非我弄错了,否则在第二个示例中,您通过调用<code>bytearray</code>并将其分配给<code>b</code>来创建{<cd1>}的副本。然后修改<code>b</code>,但返回{<cd1>}。 <code>b</code>中的修改对<code>data</code>本身没有影响。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
文本导入时标题行中的特殊字符
4 回答
文本小部件:在没有输入时更新并在循环后保持空闲
4 回答
文本小部件tkin
2 回答
文本小部件tkinter中的标签更改或文本外观更改是否有撤消功能?
8 回答
文本小部件tkinter复制图像选项
9 回答
文本小部件上的Python Tkinter ttk滚动条未缩放
4 回答
文本小部件上的滚动条可能需要根据制表符ord显示前进行滚动
4 回答
文本小部件不显示lis中的内容
9 回答
文本小部件不显示Unicode字符
2 回答
文本小部件中写入的行间距
5 回答
文本小部件中的文本作为变量
7 回答
文本小部件中的滚动条仅显示在底部
4 回答
文本小部件中的选项卡键空间计数
8 回答
文本小部件作为Lis
6 回答
文本小部件在主框架中扩展列宽
3 回答
文本小部件未使用删除功能清除
9 回答
文本小部件滚动动画(Tkinter、Python)
8 回答
文本居中。格式正确吗?
5 回答
文本差分算法
4 回答
文本已知时音频文件中的单词索引
1 回答