Is it possible to run a script file from within REPL?

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.
Post Reply
bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Is it possible to run a script file from within REPL?

Post by bittware » Wed May 18, 2022 7:21 am

Hi
I'm wondering if I can invoke a script file on the SD card from within REPL?
So that I can observe the print log through the REPL console.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Is it possible to run a script file from within REPL?

Post by Roberthh » Wed May 18, 2022 9:45 am

import pathname

Where pathname points to the python file to execute.

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: Is it possible to run a script file from within REPL?

Post by bittware » Wed May 18, 2022 12:35 pm

Roberthh wrote:
Wed May 18, 2022 9:45 am
import pathname

Where pathname points to the python file to execute.
It works. Thanks for the tip.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Is it possible to run a script file from within REPL?

Post by scruss » Wed May 18, 2022 1:26 pm

You can also do:

Code: Select all

exec(open("code.py").read())
but this is subtly different from import, if I remember right.

Post Reply