相关疑难解决方法(0)

读取二进制文件并循环遍历每个字节

在Python中,如何读取二进制文件并循环遍历该文件的每个字节?

python binary file-io

345
推荐指数
9
解决办法
75万
查看次数

Python - 打开和更改大文本文件

我有一个~600MB的Roblox类型.mesh文件,它在任何文本编辑器中都像文本文件一样读取.我有以下代码:

mesh = open("file.mesh", "r").read()
mesh = mesh.replace("[", "{").replace("]", "}").replace("}{", "},{")
mesh = "{"+mesh+"}"
f = open("p2t.txt", "w")
f.write(mesh)
Run Code Online (Sandbox Code Playgroud)

它返回:

Traceback (most recent call last):
  File "C:\TheDirectoryToMyFile\p2t2.py", line 2, in <module>
    mesh = mesh.replace("[", "{").replace("]", "}").replace("}{", "},{")
MemoryError
Run Code Online (Sandbox Code Playgroud)

以下是我的文件示例:

[-0.00599, 0.001466, 0.006][0.16903, 0.84515, 0.50709][0.00000, 0.00000, 0][-0.00598, 0.001472, 0.00599][0.09943, 0.79220, 0.60211][0.00000, 0.00000, 0]
Run Code Online (Sandbox Code Playgroud)

我能做什么?

编辑:

我不确定head,follow和tail命令在那个标记为重复的其他线程中是什么.我试图使用它,但无法让它工作.该文件也是一条巨行,它不会分成几行.

python replace out-of-memory large-files

5
推荐指数
1
解决办法
3373
查看次数

标签 统计

python ×2

binary ×1

file-io ×1

large-files ×1

out-of-memory ×1

replace ×1