Reputation: 534
I've recently moved from matlab to python and I am really missing what matlab called scritps. A script is like a function that it doesn't have variables you input or output. Instead, it sees the workspace that you are calling it in, and then everything it creates is then accessible in the workspace after its run.
(Here is a video introducing the concept of matlab scripts)
For example if your workspace is innitially the objects a
, b
and c
. If you wanted a function that gets d
from a
, b
and c
you could design it so you could call it as:
d = MyFunc(a,b,c)
Alternately if it was a script, you could call it with:
MyScript
This is useful- because if you have code that you want to segregate but run on the whole workspace you don't have to write
d = MyFunc1(a,b,c)
e = MyFunc2(a,b,c,d)
f = MyFunc2(a,b,c,d,e)
but you could instead write
MyScript1
MyScript2
Myscript3
[This is hugely useful for processing scientific data where you may have a big workspace with lots of variables- and you want to do lots of operations that take large numbers of these variables - but you want to segregate them into blocks of code that are called by a main file so its easier to read]
Upvotes: 0
Views: 353
Reputation: 66
In order to matlab-like script run, from the main_file.py:
exec(open('MyScript1.py').read())
Upvotes: 1