how to execute "OTHER" python scripts

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Posts: 10
Joined: Tue Dec 26, 2017 11:25 am

Re: how to execute "OTHER" python scripts

Post by yk22wong » Thu Mar 29, 2018 3:11 pm

benalb wrote:
Thu Mar 29, 2018 2:39 pm
I usually do this:

Code: Select all


def my_test():
    print("hello, test")

def main():

if __name__ == "__main__":
and then, can do:

Code: Select all

>>> import test01
>>> from test01 import my_test
>>> test01.my_test()
hello, test
>>> test01.main()
hello, test
>>> my_test()
hello, test
Thanks. Good to know another alternative

User avatar
Posts: 1
Joined: Wed Mar 09, 2022 12:52 pm
Location: Germany

Re: how to execute "OTHER" python scripts

Post by electricidea » Wed Mar 09, 2022 1:44 pm

Another possibility is to load and execute the script with the exec() command:

Posts: 44
Joined: Fri Sep 02, 2016 4:07 pm
Location: Austria

Re: how to execute "OTHER" python scripts

Post by lukesky333 » Wed Jun 22, 2022 8:47 am

Is it possible to execute another script and get the output of it in a variable?

something like:

Code: Select all

subprocess.getoutput('echo xyzzy')

Post Reply