(Jul-17-2020, 08:30 PM)SmukasPlays Wrote: When I execute any of the functions that are in the other files, they open but the CMD also openIt's not so common for
.py
files to execute outside the main Python file.In a package or module usage it's most common that other files are imported an not run before called in main Python file.
I guess if want to execute those files on it's own,then need to make .exe of each them with
--noconsole
.Then call the .exe and not .py file
To give a example what i talking about.
1 2 3 4 5 6 |
# life.py def foo(): return 42 if __name__ = = '__main__' : print (foo()) |
1 2 3 4 5 6 7 |
# meaning.py import life def bar(): print ( f 'The meaning of life is {life.foo()}' ) bar() |
Output:C:\code\a_folder
λ python meaning.py
The meaning of life is 42
life.py is not doing any executing on it's own but get get called in meaning.py.So it increases functionality of the main file.
If change to this.
1 2 3 4 5 |
# life.py def foo(): return 42 print (foo()) |
Output:C:\code\a_folderλ python meaning.py
42
the meaning of life is 42
No get life.py get executed on import,this rarely a wanted behavior.