Python-字典文件加密的Iso错误

Python-字典文件加密的Iso错误,python,dictionary,Python,Dictionary,这个程序应该打开一个指定的文件,读取它的内容,并使用字典将文件的内容加密到第二个文件中。它还可以打开一个加密文件,并在屏幕上显示其解密内容。我们得到了代码片段,并被告知要让它工作。我相信我的程序就在那里,但当我输入文件名时,我得到一个ISO错误,这是用于解密和加密的。我不明白为什么它找不到文件名。事实上,我确实在同一个文件夹中有我正试图挑选的文件 CODE = {'A':')','a':'0','B':'(','b':'9','C':'*','c':'8',\ '

这个程序应该打开一个指定的文件,读取它的内容,并使用字典将文件的内容加密到第二个文件中。它还可以打开一个加密文件,并在屏幕上显示其解密内容。我们得到了代码片段,并被告知要让它工作。我相信我的程序就在那里,但当我输入文件名时,我得到一个ISO错误,这是用于解密和加密的。我不明白为什么它找不到文件名。事实上,我确实在同一个文件夹中有我正试图挑选的文件

    CODE = {'A':')','a':'0','B':'(','b':'9','C':'*','c':'8',\
            'D':'&','d':'7','E':'^','e':'6','F':'%','f':'5',\
            'G':'$','g':'4','H':'#','h':'3','I':'@','i':'2',\
            'J':'!','j':'1','K':'Z','k':'z','L':'Y','l':'y',\
            'M':'X','m':'x','N':'W','n':'w','O':'V','o':'v',\
            'P':'U','p':'u','Q':'T','q':'t','U':'P','u':'p',\
            'V':'O','v':'o','W':'N','w':'n','X':'M','x':'m',\
            'Y':'L','y':'l','Z':'K','z':'k','!':'J','1':'j',\
            '@':'I','2':'i','#':'H','3':'h','$':'G','4':'g',\
            '%':'F','5':'f','^':'E','6':'e','&':'D','7':'d',\
            '*':'C','8':'c','(':'B','9':'b',')':'A','0':'a',\
            ':':',',',':':','?':'.','.':'?','<':'>','>':'<',\
            "'":'"','"':"'",'+':'-','-':'+','=':';',';':'=',\
            '{':'[','[':'{','}':']',']':'}'}
    # Constants for the menu choices
    ENCRYPT=1
    DECRYPT=2
    QUIT_CHOICE=9

    def main():
        choice = 0

        while choice != QUIT_CHOICE:
            # display the menu
            display_menu()
            #user choice
            choice = int(input('Enter your choice: '))
            # Perform action
            if choice == ENCRYPT:
                encrypt()
            elif choice == DECRYPT:
                decrypt()
            elif choice == QUIT_CHOICE:
                print('Exiting the program...')
            else:
                print('Error: invalid selection.')

    # Encryption
    def encrypt():

        #Obtain a string of converted text
        result = convert()

        #Open and write in output file
        output_name = input("Enter the name of the output file: ")
        output_file = open(output_name, 'w')
        output_file.write(result)
        output_file.close()

    # Decryption
    def decrypt():

        # obtain a string  of converted text
        result = convert()

        # write text to screen
        print(result)

    #The convert function aske the user for a file name, opens the file and converts its contents using the CODE above.
    def convert():
        input_name = input("Enter the name of the input file: ")
        input_file = open(input_name, 'r')

        result = ''
        text = input_file.read()

        #Convert all charactors but spaces.
        for ch in text:

            if ch.isspace():
                result = result + ch
            else:
                result = result + CODE[ch]

        return result

    def display_menu():
        print('        ')
        print('    Encryption/Decryption Program version 1.1')
        print('        ')
        print(' 1) Encrypt a file')
        print(' 2) Decrypt a file')
        print(' 9) Exit')

    main()
code={'A':')'、'A':'0'、'B':'('、'B':'9'、'C':'*'、'C':'8'\
"D":"D":"7","E":"6","F":"5",\
‘G’:‘美元’、‘G’:‘4’、‘H’:‘#’、‘H’:‘3’、‘I’:‘@’、‘I’:‘2’\
‘J’:‘Y’,‘J’:‘1’,‘K’:‘Z’,‘K’:‘Z’,‘L’:‘Y’,‘L’:‘Y’\
‘M’:‘X’,‘M’:‘X’,‘N’:‘W’,‘N’:‘W’,‘O’:‘V’,‘O’:‘V’\
‘P’:‘U’,‘P’:‘U’,‘Q’:‘T’,‘Q’:‘T’,‘U’:‘P’,‘U’:‘P’\
‘V’:‘O’,‘V’:‘O’,‘W’:‘N’,‘W’:‘N’,‘X’:‘M’,‘X’:‘M’\
‘Y’:‘L’,‘Y’:‘L’,‘Z’:‘K’,‘Z’:‘K’,‘Y’:‘J’,‘1’:‘J’\
“@':'I','2':'I','H','3':'H','$':'G','4':'G'\
“%”:“F”、“5”:“F”、“^”:“E”、“6”:“E”、“&”:“D”、“7”:“D”\
“*”:“C”、“8”:“C”、“(”:“B”、“9”:“B”、“)”:“A”、“0”:“A”\

“:”:”,“,”,“:”:”,“?”:”,“:”,“,”,“,”:”:“我想你的意思是
IOError
?那到底是什么-请发布你收到的完整回溯…其中包含信息。必要的…最好的猜测是你正在尝试为这两个输入/输出文件输入相同的文件名…所以更多信息。关于这一点会很有用的…给我一些时间,我关闭并重试。”我相信程序现在正在提取文件,但是,我有另一个错误。一旦我弄清楚我将从这里走向何方,我将进行编辑。