Reputation: 331
tkinter.filedialog ...
asksaveasfile() vs asksaveasfilename()
askopenfile() vs askopenfilename()
when would I use one vs the other?
Upvotes: 3
Views: 2418
Reputation: 3698
asksaveasfilename()
and askopenfilename()
return only the path to the selected file as a str
object. On the other hand, askopenfile()
and asksaveasfile()
return an actual file-like object (technically, an object of type _io.TextIOWrapper
) which you can use to read from or write to later on. For instance:
with tkinter.filedialog.askopenfile() as f:
contents = f.read()
print(contents)
Upvotes: 4