Basically I started Python a couple of days ago and wanted to create a program that could read and write files. Problem is I get this error: io.UnsupportedOperation: not writable
choice = input("Open / Create file: ")
if choice == 'Create' or choice == 'create':
new_file_name = input("Create a name for the file: ")
print(open(new_file_name, "w"))
text = input("Type to write to file: \n")
file2 = open(new_file_name)
print(file2.write(text))
print("Reading file...")
print(open(new_file_name, "r"))
print(file2.read())
elif choice == 'Open' or choice == 'open':
filename = input("File name or directory: ")
file = open(filename)
open(filename, "r")
time.sleep(1)
print("Reading file...")
time.sleep(1)
print(file.read())
choice2 = input("Write to file? Y/N \n")
if choice2 == 'Y' or choice2 == 'y':
text2 = input("Type to write to file: ")
open(filename, "w")
file = open(filename)
file.write(text2)
choice3 = input("Read file? Y/N ")
if choice3 == 'Y' or choice3 == 'y':
print(file.read())