Feb-01-2017, 11:26 PM
Hello, I am having a weird formatting error that is making me not able to run my code. I double checked all the indents to make sure they were 4 spaces. The problem is that it is causing me to get an error saying that file_output = open(output_file, "w+") output_file is not defined, which obviously it is. So this must be some sort of formatting error. It also is saying that that line is in __init__ making me think that for some reason init never actually ends.
class SimpleEncryption: file_name = "blank" def __init__(self, code_file): file_name = code_file pass def encrypt(self, input_file, output_file): file = open(input_file, "r") file_output = open(output_file, "w+") line = file.readline() while line: line_words = line.split() line_len = len(line_words) for x in range(0, line_len): file_code = open(file_name, "r") line_code = file_code.readline() check = 0 while line_code: line_code_words = line_code.split() if line_code_words[0] == line_words[x]: file_output.write(line_code_words[1]) file_output.write(" ") check = 1 line_code = file_code.readline() if check is 0: file_output.write(line_words[x]) file_output.write(" ") file_code.close() file_code = open(file_name, "r") line = file.readline() file_output.write("\n") file.close() file_output.close() pass def decrypt(self, input_file, output_file) : file = open(input_file, "r") file_output = open(output_file, "w+") line = file.readline() while line: line_words = line.split() line_len = len(line_words) for x in range(0, line_len): file_code = open(file_name, "r") line_code = file_code.readline() check = 0 while line_code: line_code_words = line_code.split() if line_code_words[1] == line_words[x]: file_output.write(line_code_words[0]) file_output.write(" ") check = 1 line_code = file_code.readline() if check is 0: file_output.write(line_words[x]) file_output.write(" ") file_code.close() file_code = open(file_name, "r") line = file.readline() file_output.write("\n") file.close() file_output.close() pass