UnboundLocalError: local variable 'fullfilename' referenced before assignment

前端 未结 1 1158
灰色年华
灰色年华 2021-01-22 19:34

I\'m facing an error as:

UnboundLocalError: local variable \'fullfilename\' referenced before assignment

Code block:

caminho_pa         


        
相关标签:
1条回答
  • 2021-01-22 20:35

    This error message...

    UnboundLocalError: local variable 'fullfilename' referenced before assignment
    

    ...implies that you have referenced the variable fullfilename even before it was assigned any value.


    In your code block:

    for arquivo in arquivos:
        if arquivo.endswith(".zip"):
            fullfilename = os.path.join(caminho_path, arquivo)
    

    the variable fullfilename is assigned a value only when the condition arquivo.endswith(".zip") is true. Else the variable fullfilename remains unassigned.

    In one of such cases when the variable was left unassigned, you have tried to reference it at a later part in your code as:

    with ZipFile(fullfilename, 'r') as zipObj:
    

    Even when the variable fullfilename was still unassigned. Hence you see the error.

    0 讨论(0)
提交回复
热议问题