[Python] why I am getting SyntaxError: 'yield' outside function?

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use PyCharm to read a locked excel file and I used the following code:

    with open('abcd.xlsm', 'rb') as abcd1:
    excel = msoffcrypto_OfficeFile('abcd.xlsm')
    excel.load_key('1234')
    excel.decrypt(temp)
    abcd1.seek(0, os.SEEK_END)
    while True:
    lines = abcd1.readline()
    if not lines:
    time.sleep(0.1)
    continue
    yield lines


    Can anyone tell me what's wrong with this yield function? I have been getting


    [SyntaxError: 'yield' outside function]
    ​

    I am new to python so I would appreciate some help, thank you so much!

    Continue reading...

Compartilhe esta Página