[英]How to convert dat file to readable text using python
I am techy102 and I want to know how to convert a dat file to readable text using python, for an upcoming project I wanted to know this information, here is my code:我是 techy102,我想知道如何使用 python 将 dat 文件转换为可读文本,对于即将到来的项目,我想知道这些信息,这是我的代码:
import pickle
x = input("enter something: ")
with open('savefile.dat', 'wb') as f:
pickle.dump(x, f, protocol=2)
with open('savefile.dat','rb') as ff:
print(ff)
and it gives me this:它给了我这个:
<_io.BufferedReader name='savefile.dat'>
Does anyone know how to actually convert the contents to readable text?有谁知道如何将内容实际转换为可读文本?
You have to unpickle what you pickle using the pickle.load
function.你必须使用pickle.load
function 解开你腌制的东西。
import pickle
x = input("enter something: ")
with open('savefile.dat', 'wb') as f:
pickle.dump(x, f, protocol=2)
with open('savefile.dat','rb') as ff:
x1 = pickle.load(ff)
print(x1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.