如何读取zip文本文件?

2024-10-04 11:33:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图读取python中的压缩文件(.gz),但遇到了问题。你知道吗

import gzip
import gensim
import logging
import os

logging.basicConfig(
    format='%(asctime)s : %(levelname)s : %(message)s',
    level=logging.INFO)

data_file = r"C:\\PythonProgs\\OpinRank.gz"

def show_file_contents(input_file):
    with gzip.open(input_file, 'rb') as f:
        for i, line in enumerate(f):
            print(line)
            break


show_file_contents(data_file)

我本想读zip文件,但实际上给了我这个错误:

FileNotFoundError:[Errno 2]没有这样的文件或目录:“C:\PythonProgs\OpinRank.gz公司'


Tags: 文件importinputdataloggingshowlinecontents