What is the scope of if __name__ == __main__? Is everything covered by this statement in global space ?
What is the scope of if __name__ == __main__ ? Is everything covered by
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is nothing special about
if __name__ == '__main__'block whatsoever. That is to say, its scope is determined by the place it occurs. Since such blocks typically occur at top-level, their scope is global.If this block were to occur in a function, which is perfectly legal, its scope would be local—except that
__name__would still resolve to the global value defined in the module.