![](/img/trans.png)
[英]How to convert the content of a .dat file to a human readable form using Python?
[英]How to convert dat file to readable text using python
我是 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)
它給了我這個:
<_io.BufferedReader name='savefile.dat'>
有誰知道如何將內容實際轉換為可讀文本?
你必須使用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.