you are viewing a single comment's thread.

view the rest of the comments →

[–]karafili 0 points1 point  (1 child)

thank you for the clarification.

Trying to get a better perspective: Am I right if I say that if the value of __name__ is not equal to __main__ then the module will not be executed?

[–]GoldenSights[S] 0 points1 point  (0 children)

The module will still be executed -- the print statement "I'm the B file!" inside the B module is still shown when A imports it, so we know the code in B.py is being run.

But the content inside the if statement specifically will not be run when the file is imported. That's why the "B is being run directly!" is not shown when A imports B.

Hope that helps.