with open("filename.txt","r") as f:
contents = f.read()
with open(file_path+file_name*, 'wb') as a:
a.write(content)
# *example: r"C:UsersuserDesktophello_world.docx".
# 'hello_world' DOENT EXIST at the moment, python will automatically create it for us
Simple way to get a directory of a file and open it:
from tkinter.filedialog import askopenfilename
filename = askopenfilename()
# read, write, close a file
# catch error if raise
try:
file = open("tryCatchFile.txt","w")
file.write("Hello World")
file = open("tryCatchFile.txt", "r")
print(file.read())
except Exception as e:
print(e)
finally:
file.close()