读取Python文件失败并出现MemoryError

时间:2020-04-03 00:58:19

标签: python memory file-copying

我正在尝试运行下面的代码,该代码过去工作正常,但现在出现内存错误。

def gunzip_shutil(source_filepath, dest_filepath, block_size=10000000): 
    with gzip.open(source_filepath, 'rb') as s_file, \
            open(dest_filepath, 'wb') as d_file:
        s_file.seek(3)
        shutil.copyfileobj(s_file, d_file, block_size)
        s = open(dest_filepath, mode='r', encoding='utf-8-sig').read()
        open(dest_filepath, mode='w', encoding='utf-8').write(s)
    logging.info('File unzipped.')

下面是错误消息:

gunzip_shutil(文件路径,目标文件)
在gunzip_shutil
中,文件“ C:/Users/Shahsa/PycharmProjects/mymisc/recon_json.py”第227行 s = open(目标文件路径,mode ='r',encoding ='utf-8-sig')。read()
MemoryError

有什么解决方法吗?

0 个答案:

没有答案