Page 1 of 1

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

Posted: Wed May 18, 2022 7:21 am
by bittware
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.

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

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

Where pathname points to the python file to execute.

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

Posted: Wed May 18, 2022 12:35 pm
by bittware
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.

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

Posted: Wed May 18, 2022 1:26 pm
by scruss
You can also do:

Code: Select all

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