0

Why This Programs show Error. if __name__ == '__main__':

def name(name): print(f"This Is {name}") if __name__ == '__main__': name("ahmed") When i import this program to another program this program show error.

9th Apr 2020, 6:19 PM
Syed Ahmed Raza Shah
Syed Ahmed Raza Shah - avatar
1 Resposta
+ 1
Because you imported it. if __name__ = '__main__': pass is a check that sees if the module with said code is in fact the "main" module (the module you are currently working in) if you import a module with that code, that module is now not the "main" module. So now, importedmodule != '__main__'. The code either wont run or raise an exeption
12th Apr 2020, 10:59 AM
Slick
Slick - avatar