Reputation: 107
I want my entries to be saved in a file
filename= filedialog.asksaveasfile(mode="wb",defaultextension=".txt")
with open(filename, "wb") as f:
dill.dump(data,f)
This code gives an error. Is there any other way of doing it.
TypeError: invalid file: <_io.BufferedWriter name='C:/Users/random.txt'>
Upvotes: 0
Views: 86
Reputation: 7735
filedialog.asksaveasfile
returns an opened file. Hence you are getting an error when you are trying open it again. Just try to use it as it was opened before.
file= filedialog.asksaveasfile(mode="wb",defaultextension=".txt")
if file is not None: # returns `None` if cancel's out
dill.dump(data,file)
Upvotes: 2