你好,编译器忽略了 if/elif 语句,我不知道为什么我添加了一些印刷品以了解问题的根源,但我没有明白def decode_frame(frame_dir, caesarn): #take the first frame to get width, height, and total encoded frame # first_frame = Image.open(str(frame_dir) + "/0.jpg") first_frame = Image.open(str(frame_dir) + "/" + "1.png") print("1") r, g, b = first_frame.getpixel((0, 0)) print("2") total_encoded_frame = g print("3") msg = "" print("4") for i in range(1, total_encoded_frame+1): print("5") frame = Image.open(str(frame_dir) + "/" + str(i) + ".png") print("6") width, height = frame.size index = 0 print("7") for row in range(height): print("8") for col in range(width): print("10") try: print("9") r, g, b = frame.getpixel((col, row)) print("11") except ValueError: print("12") # for some ong a(transparancy) is needed r, g, b, a = frame.getpixel((col, row)) print("13") print("aa") if row == 0 and col == 0 : print("14") length = r print("15") elif index <= length: # put the decrypted character into string print("tt") msg += caesar_ascii(chr(r), "dec", caesarn) print("18") index += 1 print("cc") #remove the first and the last quote msg = msg[1:-1] print("17") recovered_txt = open("data/recovered-text.txt", "w") print("19") recovered_txt.write(str(msg.encode().decode('string_escape'))) print("20")这是输出911aa1810911aa1810911aa1810911aa1810911aa1810911aa1810911aa1810911aa18cc1719
1 回答
偶然的你
TA贡献1841条经验 获得超3个赞
错误消息表明错误在行中:
recovered_txt.write(str(msg.encode().decode('string_escape')))
特别是,该decode
方法不知道什么'string_escape'
意思;它需要编码的名称,例如'utf-8'
.
您正试图msg
通过四个修改:[1:-1]
、encode
和decode
; str
这可能不是你想要的。你可能想要的是写出msg
文本:
recovered_txt = open("data/recovered-text.txt", "wt") recovered_txt.write(msg)
注意"wt"
通话中的open
。
添加回答
举报
0/150
提交
取消