+ 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?
2 ответов
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?
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"