I am using pickle to store variables as:
pickle.dump(database,open("save.p", "wb"))
Here database is the variable (type dictionary) I am trying to store and save.p is the destination file.
Now I want to replace this as
pickle.dump(database,open("%s"%var, "wb"))
Here var
is taken from stdin. Basically letting the user specify the file.
However just writing this does not do the trick.
The pickle documentation suggests that a new file for the given name will be created if not found in the specified path.
What I have tried:
pickle.dump(database,open(var, "wb"))
to see if it can access the variable directly and pickle.dump(database,open("%s", "wb")%var)
.
I am missing something very obvious here. But can't figure out what.
EDIT: I suppose there was some error with permissions. I now create the file with write permissions before running the script and it works. Thank you everyone.