import os os.path.isdir('C:\ProgramData\Pk') if True: pass else: newpath = r'C:\ProgramData\Pk'# здесь ошибка if not os.path.exists ( newpath ): os.makedirs ( newpath ) 

Writes that the variable is not defined in what was wrong and how to fix it?

    1 answer 1

    The else block will never be executed for obvious reasons, and therefore the variable newpath will not be declared and initialized.