.npy 和 .pkl 、正常文件的打开方式

对于.npy文件,可以使用代码打开

import numpy as np
test = np.load('test.npy', encoding = 'latin1')
print(test)

对于.pkl文件,可以使用代码打开 

import pickle as pkl
f = open('test.pkl', 'rb')
b = p.load(f)
b = list(b)
b = np.array(b)
print(b)

对于正常文件,使用代码打开

1)
import json
with open("test.json") as f:
    text = f.read()

t = json.loads(text)
print(t)

2)
f = open("test.json", encoding = 'utf-8')
text = f.read()
f.close()

猜你喜欢

转载自blog.csdn.net/jiangchao98/article/details/118945821