+ 1

Can somebody explain the use of __name__==__main__ in Python?

4th Feb 2020, 5:16 AM
Tharindu
Tharindu - avatar
5 Réponses
+ 4
In addition to what previous fellows said, you can use __name__ attribute to run your script as a stand alone program. if __name__ == __main__
4th Feb 2020, 8:16 AM
Manos Manik
Manos Manik - avatar
+ 3
Jan Markus wow 👍
4th Feb 2020, 5:41 AM
Sebastian Keßler
Sebastian Keßler - avatar
+ 3
By using this you can choose a part of a file (or all of the file) to be run only if that file is not imported. On the other words if it's the main file.
4th Feb 2020, 8:10 AM
Qasem
+ 1
Thank you all for the helpful answers..!
4th Feb 2020, 11:49 PM
Tharindu
Tharindu - avatar