My code takes a regular paragraph file and switches it up to ROT13 characters.
I keep getting the error ("TypeError: write() argument must be str, not None") and have no idea why/what it's talking about.
My code works fine outputting everything correctly into the file, but this error is really bugging me.
Function
# Constants
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ROT13_ALPHABET = "NOPQRSTUVWXYZABCDEFGHIJKLM"
def code_ROT13(file_variable_input, file_variable_output):
line = file_variable_input.readline().strip()
alphabet_list = list(ALPHABET)
rot13_list = list(ROT13_ALPHABET)
while line != "":
for letter in line:
rot13_edit = False
for i in range(len(alphabet_list)):
if letter == alphabet_list[i] and not rot13_edit:
letter = rot13_list[i]
rot13_edit = True
elif letter == alphabet_list[i].lower() and not rot13_edit:
letter = rot13_list[i].lower()
rot13_edit = True
file_variable_output.write(letter)
line = file_variable_input.readline()
Main
# Imports
from cipher import code_ROT13
# Inputs
file_name_input = input("Enter input file name: ")
file_name_input = "code.txt"
file_variable_input = open(file_name_input, "r")
file_name_output = input("Enter output file name: ")
file_name_output = "code_ROT13.txt"
file_variable_output = open(file_name_output, "w")
# Outputs
editversion = code_ROT13(file_variable_input, file_variable_output)
file_variable_output.write(editversion)
file_name_input.close()