Python忽略if/elif语句

Python忽略if/elif语句,python,python-3.x,pycharm,decoding,steganography,Python,Python 3.x,Pycharm,Decoding,Steganography,您好,编译器忽略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 = Ima

您好,编译器忽略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")
def解码帧(帧方向,凯撒):
#获取第一帧以获取宽度、高度和总编码帧
#第一帧=Image.open(str(frame\u dir)+“/0.jpg”)
第一帧=Image.open(str(frame\u dir)+“/”+“1.png”)
打印(“1”)
r、 g,b=第一帧。getpixel((0,0))
打印(“2”)
总编码帧=g
打印(“3”)
msg=“”
打印(“4”)
对于范围内的i(1,总编码帧+1):
打印(“5”)
frame=Image.open(str(frame_dir)+“/”+str(i)+“.png”)
打印(“6”)
宽度、高度=帧大小
索引=0
打印(“7”)
对于范围内的行(高度):
打印(“8”)
对于范围内的列(宽度):
打印(“10”)
尝试:
打印(“9”)
r、 g,b=frame.getpixel((列,行))
打印(“11”)
除值错误外:
打印(“12”)
#有些情况下,需要透明性
r、 g,b,a=frame.getpixel((列,行))
打印(“13”)
印刷品(“aa”)
如果行==0且列==0:
打印(“14”)
长度=r
打印(“15”)

elif index错误消息表明错误在以下行中:

recovered_txt.write(str(msg.encode().decode('string_escape'))
特别是,
解码
方法不知道
'string\u escape'
的意思;它需要编码的名称,如
'utf-8'

您正试图通过四个修改来传递
msg
[1:-1]
编码
解码
str
;这可能不是你想要的。您可能希望将
msg
写为文本:

recovered_txt=open(“data/recovered text.txt”,“wt”)
已恢复的_txt.write(msg)

注意
打开
调用中的
“wt”

您会发现学习使用调试器非常宝贵。。。