[英]Python ignoring if/elif statement
Hello the compiler ignore if/elif statement and i dont know why您好编译器忽略 if/elif 语句,我不知道为什么
i added some print to know the source of the problem but i didnt get it我添加了一些打印以了解问题的根源,但我没有得到它
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")
here is the output这是 output
9
11
aa
18
10
9
11
aa
18
10
9
11
aa
18
10
9
11
aa
18
10
9
11
aa
18
10
9
11
aa
18
10
9
11
aa
18
10
9
11
aa
18
cc
17
19
Traceback (most recent call last):
File "C:/Users/HP/Aniss/PycharmProjects/Caesar-Cipher-Video-Steganography-master/main.py", line 103, in <module>
decode_frame("temp", caesarn)
File "C:\Users\HP\Aniss\PycharmProjects\Caesar-Cipher-Video-Steganography-master\functions.py", line 166, in decode_frame
recovered_txt.write(str(msg.encode().decode('string_escape')))
LookupError: unknown encoding: string_escape
Process finished with exit code 1
The error message indicates that the error is in the line:错误消息表明错误在以下行中:
recovered_txt.write(str(msg.encode().decode('string_escape')))
In particular, the decode
method doesn't know what 'string_escape'
means;特别是
decode
方法不知道'string_escape'
是什么意思; it's expecting the name of an encoding, like 'utf-8'
.它期望编码的名称,例如
'utf-8'
。
You're trying to pass the msg
through four modifications: [1:-1]
, encode
, decode
and str
;您正在尝试通过四个修改来传递
msg
: [1:-1]
、 encode
、 decode
和str
; this is probably not what you want.这可能不是你想要的。 What you probably want is to write out
msg
as text:您可能想要的是将
msg
写为文本:
recovered_txt = open("data/recovered-text.txt", "wt")
recovered_txt.write(msg)
Note the "wt"
in the open
call.请注意
open
呼叫中的"wt"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.