The statements in the global scope of imported modules are executed when they are imported. So, you may consider adding function calls or other desired statements in the global scope. Let me give an example:
Game.py
:
def main():
print("game")
main()
Typing_Question_Screen.py
:
def test():
print("tqs")
test()
The importing file:
from Game import *
from Typing_Question_Screen import *
print("import complete")
The output of this file would be:
game
tqs
import complete
Note that you can check whether the module is being executed independently. (Please keep in mind that usually the opposite of this behavior is used, and generally imports are not expected to execute code by themselves.)
For example, the below implementation calls main
only if the module is being imported:
def test():
print("tqs")
if __name__ != __main__:
test()
__name__
, a special variable of the module set by the interpreter, is __main__
when the module is run without being imported.
Also, I would avoid importing with *
. Moreover, the imports should be at the top of the importing file, separated from other statements and definitions. See: PEP8 on importing
I think you may modify your code as:
import Game
import Typing_Question_Screen
Game.main()