I have a ~600MB Roblox type .mesh file, which reads like a text file in any text editor. I have the following code below:
mesh = open("file.mesh", "r").read()
mesh = mesh.replace("[", "{").replace("]", "}").replace("}{", "},{")
mesh = "{"+mesh+"}"
f = open("p2t.txt", "w")
f.write(mesh)
It returns:
Traceback (most recent call last):
File "C:\TheDirectoryToMyFile\p2t2.py", line 2, in <module>
mesh = mesh.replace("[", "{").replace("]", "}").replace("}{", "},{")
MemoryError
Here is a sample of my file:
[-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]
What can I do?
Edit:
I'm not sure what the head, follow, and tail commands are in that other thread that marked this as a duplicate. I tried to use it, but couldn't get it to work. The file is also one giant line, it isn't split into lines.
You need to read one bite per iteration, analyze it and then write to another file or to
sys.stdout
. Try this code:UPD:
It works really slow (thanks to jamylak). So I've changed it:
So now it's working ~15 sec on 1.4G file. To run it: