簡體   English   中英

在文本文件Python中存儲和調用變量

[英]Store and recall a variable in a text file Python

我如何將變量x存儲在文本文件中的特定行(第一行)上,並在程序打開時恢復它。

另外我如何將數據存儲在特定行的文本文件中

您應該看看內置的open()

#To write to a file:
with open("file.txt", "w") as f:
    f.write("Data!")

#To read from a file:
with open("file.txt", "r") as f:
    print(f.read())

下次,您應該檢查重復項:

在python中輕松保存/加載數據將最高分數寫入數據文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM