I have a file with a list and 3 functions in it; view, append and sort functions.
I want to use pickle to save data changes in to another file inorder to retrive it next time.
I have a list, when i call function VIEW, i see the primary list i created. When i call APPEND function, i can append a new word and see it with print in that function. But if i call VIEW function again, i see the primary list again without any data changes (the append word).
I know i should use:
import pickle pickle.dump(favorite_movies, open("films.db", "wb")) favorite_movies = pickle.load( open("films.db", "rb"))
Now my problem is that where should i type pickle.dump and pickle.load in the main file.
In the first line above all codes?
Inside each function?
Or somewhere in this part:
if __name__ == "__main__": import argparse parser = argparse.ArgumentParser(description='Execute a function') parser.add_argument('funcname', help='name of function to execute', metavar='FUNCNAME', choices=['view' , 'sort' , 'append']) args = parser.parse_args() function = globals()[args.funcname] function()
I'm almost new to programming, so this is the problem i have now with this little project.