Reputation: 384
I have a Main script in Spyder that calls several functions contained in 6 different scripts (.py). I had to this way because the scripts are also used in different projects.
Currently, I have to run each script (containing several functions each) separately by hand, which is tiring, by clicking in the "green triangle" before launching the Main Script so that the functions contained in each script are stored in the working environment.
My question is: Would it be possible to automatically run each script directly from the Main Script and not running one after the another by hand?
Upvotes: 0
Views: 3805
Reputation: 311
Try
from filename import *
instead of
import filename
No .py extension in the import.
Upvotes: 1
Reputation: 19885
When you execute an import
statement, the source file being imported is executed. So, for example, if you have thing.py
and you execute import thing
, all the code in thing.py
will be run.
Also, as noted in a comment by Sven Krüger: you can use runpy.run_path
, which I think is overall a better solution than my original suggestion.
Upvotes: 1