1file = open("text.txt", "w")
2file.write("Your text goes here")
3file.close()
4'r' open for reading (default)
5'w' open for writing, truncating the file first
6'x' open for exclusive creation, failing if the file already exists
7'a' open for writing, appending to the end of the file if it exists
1import pickle
2file_name = 'data_stuff'
3try:
4 # this will create the file if it doesnt already exist
5 history_data = open(file_name + ".dat", "x")
6 history_data.close()
7 history_data = []
8 pickle.dump(history_data, open(file_name + ".dat", "wb"))
9except:
10 # if the file already exist it will load the history_data array
11 # you can add to it or modity it or just read it.
12 history_data = pickle.load(open(file_name + ".dat", "rb"))
13
14print(history_data) #this will print the history_data array that was stored in the file
15foo = 5
16history_data.append(foo)
17print(history_data)
18pickle.dump(history_data, open(file_name + ".dat", "wb")) # this saves the newly modified history_data to the file