How to unpack xz file with python which contains only data but no filename?

后端 未结 1 1192
失恋的感觉
失恋的感觉 2021-01-17 23:38

I have a file, which I can decompress under linux using the following command:

unxz < file.xz > file.txt

How can I do the same using

相关标签:
1条回答
  • 2021-01-17 23:55

    The tarfile module is only for... err... tar files. What you have here is not one.


    XZ support is available in Python 3.3's LZMA module. In Python 2.x, you need backports.lzma.

    try:
        import lzma
    except ImportError:
        from backports import lzma
    
    print lzma.open('file.xz').read()
    
    0 讨论(0)
提交回复
热议问题