Head First Python--test for pickle load

本文介绍了一个Python脚本,该脚本使用pickle模块来加载之前保存的对象数据,并使用nester模块打印这些数据。脚本尝试从'd:/Python_test'目录下的'man.txt'和'other.txt'文件中加载数据,并处理可能出现的IO错误和pickle错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import os
import pickle
import nester

os.chdir('d:/Python_test')
new_man = []
new_other = []
try:
    with open('man.txt', 'rb') as man_file:
        new_man = pickle.load(man_file)
    with open('other.txt', 'rb') as other_file:
        new_other = pickle.load(other_file)
except IOError as err:
    print('File error! ' + str(err))
except pickle.PickleError as perr:
    print('Pickling error: ' + str(perr))

nester.print_lol(new_man)
nester.print_lol(new_other)

Traceback (most recent call last): File "tools/test.py", line 230, in <module> main() File "tools/test.py", line 184, in main checkpoint = load_checkpoint(model, args.checkpoint, map_location="cpu") File "/home/wangbaihui/anaconda3/envs/vad/lib/python3.8/site-packages/mmcv/runner/checkpoint.py", line 531, in load_checkpoint checkpoint = _load_checkpoint(filename, map_location, logger) File "/home/wangbaihui/anaconda3/envs/vad/lib/python3.8/site-packages/mmcv/runner/checkpoint.py", line 470, in _load_checkpoint return CheckpointLoader.load_checkpoint(filename, map_location, logger) File "/home/wangbaihui/anaconda3/envs/vad/lib/python3.8/site-packages/mmcv/runner/checkpoint.py", line 249, in load_checkpoint return checkpoint_loader(filename, map_location) File "/home/wangbaihui/anaconda3/envs/vad/lib/python3.8/site-packages/mmcv/runner/checkpoint.py", line 266, in load_from_local checkpoint = torch.load(filename, map_location=map_location) File "/home/wangbaihui/anaconda3/envs/vad/lib/python3.8/site-packages/torch/serialization.py", line 608, in load return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args) File "/home/wangbaihui/anaconda3/envs/vad/lib/python3.8/site-packages/torch/serialization.py", line 777, in _legacy_load magic_number = pickle_module.load(f, **pickle_load_args) EOFError: Ran out of input -------------------------------------------------------------------------- Primary job terminated normally, but 1 process returned a non-zero exit code. Per user-direction, the job has been aborted. -------------------------------------------------------------------------- -------------------------------------------------------------------------- mpirun detected that one or more processes exited with non-zero status, thus causing the job to be terminated. The first process to do so was: Process name: [[15407,1],0]
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值