Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with formatting
#1
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
Reply


Messages In This Thread
Help with formatting - by hellboy632789 - Feb-01-2017, 11:26 PM
RE: Help with formatting - by meems - Feb-01-2017, 11:55 PM
RE: Help with formatting - by hellboy632789 - Feb-02-2017, 12:01 AM
RE: Help with formatting - by meems - Feb-02-2017, 12:39 AM
RE: Help with formatting - by Larz60+ - Feb-02-2017, 01:42 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020