Bge script - open file in zip

Hello,
I want a script that can read text files in zip archives. the text object in the game should take values from the text file. I tried to use a script to python from internet to open the zip archive, but the blender threw me an error.

pfile
archive = zipfile.ZipFile('mail.zip', 'r')
#Let us verify the operation..
txtdata = archive.read('mail.txt')
print(txtdata)

Please could anyone write me a script that would work as i describe. Might be another type of archive.

With 7Zip, I created a zip file containing a textfile with a charset and then put it in my D: drive. Testing the exact same script, it worked just fine:

import zipfile;
archive = zipfile.ZipFile('D:\CHR64.zip', 'r')
txtdata = archive.read('CHR64.txt')
print(txtdata)

So my guess is you tried to open another kind of file; 7z won’t work, and rar won’t work.

Sadly, I can’t know if something else happened because you didn’t post the error. Mind reading is tough, man.

Please, can you send me blender.file?
I try your script, but same as before. Here is that error

Ah, the \U in \Users is being interpreted as an escape.

Two solutions:

  • Double the backslashes \\
  • Make the path a raw string, ie r"C:\Users\..."