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.
1 Antwort
+ 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