AttributeError: 'module' object has no attribute 'open'

后端 未结 2 924
北海茫月
北海茫月 2021-01-28 08:52

I am trying to open a .csv compressed to a .lzma file in Linux using the following code:

import lzma
import pandas as pd

myfile= \'/home/stacey/work/roll_158_oe         


        
2条回答
  •  -上瘾入骨i
    2021-01-28 09:29

    Apparently you need to call a class from the lzma module to open the file:

    import lzma  # python 3, try lzmaffi in python 2
    with open('one-csv-file.xz') as compressed:
        with lzma.LZMAFile(compressed) as uncompressed:
            for line in uncompressed:
                do_stuff_with(line)
    

    Extracted from How to open and read LZMA file in-memory

提交回复
热议问题