我有一个〜600MB的Roblox类型.mesh文件,它在任何文本编辑器中都像文本文件一样读取。下面我有以下代码:Python - 打开并更改大型文本文件
mesh = open("file.mesh", "r").read()
mesh = mesh.replace("[", "{").replace("]", "}").replace("}{", "},{")
mesh = "{"+mesh+"}"
f = open("p2t.txt", "w")
f.write(mesh)
它返回:
Traceback (most recent call last):
File "C:\TheDirectoryToMyFile\p2t2.py", line 2, in <module>
mesh = mesh.replace("[", "{").replace("]", "}").replace("}{", "},{")
MemoryError
这里是我的文件的样本:
[-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]
我能做些什么?
编辑:
我不知道什么头,跟着,和尾命令是在这个标记为重复的其他线程。我试图使用它,但无法使它工作。该文件也是一个巨大的线,它不分成线。
尝试做替换的一次一个。尝试阅读一些教程。 – wwii
这并没有工作 – GShocked
可能的重复[在Python中读取大文本文件,一行一行地将其加载到内存中](http://stackoverflow.com/questions/6475328/read-large-text-files-in -python-line-by-line-without-loading -in-to-memory) –