I'm learning with python and I can't find a working solution for my question. I have some .xml files in .7z file. I want to read the .xml files with python but I can't extract them on disk. I tried this with lzma.open('test.7z', 'r') as lf:
but it gaves me "AttributeError: 'module' object has no attribute 'open'". This looked as a good solution, but I don't have py7zlib on a server, where the script has to works. But I can ask an admin to install it. Anyway I can't find anywhere, which solution would work for this. I googled for more than one hour, sunk in a deep water of google and found nothing. I'll be glad for every answer. If I badly described my problem, I'll try better but I'm not a native english speaker so my vocabulary isn't infinite. Thanks
Asked
Active
Viewed 638 times
1
-
can you open the file via the command line? – Maximilian Peters Apr 30 '16 at 19:22
-
Don't know what you think exactly. I would like the script to work like this `./python.py file.7z` . – D. Pol Apr 30 '16 at 19:54
-
Is something like 7zip installed on the server you are using? – Maximilian Peters Apr 30 '16 at 20:01
-
1Yes it is. There's p7zip. – D. Pol Apr 30 '16 at 20:03
-
You can use subprocess.Popen or call to call the program from your python script and then proceed with the generated files: https://docs.python.org/3.5/library/subprocess.html – Maximilian Peters Apr 30 '16 at 20:13
-
But that would mean that I have to extract .7z file to disk? Or am I wrong? – D. Pol Apr 30 '16 at 20:37
-
Yes, you would need to save the files. PyLZMA seems to support streaming. What kind of server are you using? If it is a Windows server you download the binaries here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pylzma – Maximilian Peters Apr 30 '16 at 20:49
-
It's CentOS Linux. I'll look into PyLZMA. Thanks – D. Pol May 01 '16 at 09:33