Page 1 of 1

Main.py vs Boot.py

Posted: Sat Jan 19, 2019 5:32 pm
by ajocius
Is there any general logic on what to keep in each file? Both files are executed during startup. I have seen examples where wifi connection is coded in boot.py, but also seen it in main.py, tried both options and it worked fine. Same with MQTT parameters (user name, password, ip address, etc), some place them in boot.py , some in main.py. Is there any benefit of putting into one file vs the other?

Re: Main.py vs Boot.py

Posted: Sat Jan 19, 2019 7:28 pm
by dhylands
The way that I normally think about this is that boot.py is used to configure your bootup and main.py is my main program.

Some things, like configuring the USB mode, or setting the name of the main script (which defaults to main.py, but can be changed) can only be done in boot.py.

Code which is introduced in boot.py is availaed at the REPL without having to import anything, whereas code from main.py isn't. I think of it as boot.py is sourced where main.py is imported.