在文本文件Python中存储和调用变量

在文本文件Python中存储和调用变量,python,python-3.x,python-3.4,Python,Python 3.x,Python 3.4,如何将变量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()) 下次,您应该检查是否存在重复项:

如何将变量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())
下次,您应该检查是否存在重复项: