+ 1

__name__ __main__

Обшарил весь интернет, ну никак не пойму для чего нужно: If __name__ == "__main__" Типо чтобы программа, в какой-то момент выполняла только "свой код", без импортированных модулей? Типо разделитель? ----------------------------------------------------------------- Searched the entire Internet, well, I do not understand this line: If __name__ = = "__main__" As like, to program, in some moment fulfilled only "its code", without imported modules? Like a separator?

24th Oct 2019, 6:35 AM
Raygner Akuev
Raygner Akuev - avatar
2 odpowiedzi
0
Jay, I know it, but for what? What is the main idea of __name__ == __main__? To separate peace of code, which will run (as a module) and not run(as a main code) , when we imports this project to another project?
24th Oct 2019, 7:41 AM
Raygner Akuev
Raygner Akuev - avatar
0
For example: # project_1 def checker() : If name == "__main__": print ("it's native code") If True: print ("only for import") ###prints both _____________________________________ # project_2 Import project_1 project_1.checker() ###prints "only for import"
24th Oct 2019, 7:48 AM
Raygner Akuev
Raygner Akuev - avatar