Skip to content Skip to sidebar Skip to footer

Why Is Nothing Running If I Import A Module?

I'm importing a module but when I run it, it says Process finished with exit code 0 My code: from Game import * I've tried everything that's been suggested and I even looked at ans

Solution 1:

The whole point of the if __name__ == 'main'block is to stop the code inside it from running when importing that script as a module; only the "main" script, the one you're directly executing, will execute the code within that statement. If you just replace that statement with a direct call to main(), then that function will run upon import.

For more info, see: What does if __name__ == "__main__": do?

If you want to execute Game's main from your script, your code would have to look like:

from Game import *
main()

Post a Comment for "Why Is Nothing Running If I Import A Module?"