python 中的 DAT 文件

DAT file in python

我对 Python 中的 .dat 文件有疑问:我无法对其进行编码。我已经尝试过 UTF-8、ASCII 等等。

import re

with open("mixture1.dat",'r', encoding="ascii", errors="surrogateescape") as f:
    lines = f.readlines()
    text = "".join(lines)

print(text)

这是“mixture1.dat”的the link。应该有化学相关的东西,但是我一个星期都打不开。我应该怎么做?

编辑:解决方案

import pickle

def read_file(filename):
    with open(filename,  'rb')  as  FID:
        mp  = pickle.Unpickler(FID)
        data = mp.load()
    return data

工作正常

您可以使用 numpy 这样做:

import numpy as np
data = np.fromfile('mixture1.dat', dtype=float)

print(data.size)
print(data[:20])

输出:

23767
[ 5.43235748e-312  7.01653493e-205  3.63521590e+228  9.77081644e+199
  4.03065734e-277 -2.37251204e-214  9.10016855e+276  4.27255706e+180
 -2.89898361e-211 -8.83065826e-211  3.49131717e+070  1.91561942e+053
 -3.80240360e-210  2.67555322e-318 -8.83065517e-211 -5.81601764e+181
 -5.71181552e-277  8.93904783e+014  3.37067979e-234  3.07882662e-292]