How to achieve this feature available in IDLE

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

How to achieve this feature available in IDLE

Post by liudr » Sun Oct 22, 2017 4:31 am

If you load a script into IDLE and run it, then you can go to the shell window to continue to enter code. Say you defined a variable a=10 in the script you run inside IDLE, then in shell window you can use this variable like b=a**2. Then b=100.

The reason I am looking to achieve this feature is to predefine a bunch of useful functions and then once I am at MicroPython's prompt, I can easily run these functions. I thought I could write all the code in a script say mycode.oy and use "from mycode import *".

I am curious, whether this is the right way to go about it.
Also, how do I automatically run the "from mycode import *" at the starting point of the interactive shell?

Thanks.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: How to achieve this feature available in IDLE

Post by deshipu » Sun Oct 22, 2017 9:06 am

It just works. Anything you put in main.py gets executed, and when the program finishes or is interrupted, you get access to all the local variables in the REPL.

User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: How to achieve this feature available in IDLE

Post by liudr » Sun Oct 22, 2017 4:33 pm

Great! Thanks. I was using ampy to upload files. I must have thought that uploading files makes the board reset (Arduino like). It's not. I have to ctrl + D to soft reset. It's all working now! Beautiful!

Post Reply