This page (revision-21) was last changed on 2025-07-30 13:27 by Murray Altheim

This page was created on 2025-07-30 02:24 by Murray Altheim

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
21 2025-07-30 13:27 826 bytes Murray Altheim to previous

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 3 added one line
%%info
At line 5 added one line
%%
At line 5 removed one line
The file {{main.py}} is special in MicroPython, only in the sense that when you power-on the device and/or press the reset button, the main.py file is executed.
At line 8 added 2 lines
The file (also sometimes called a "script") named {{main.py}} is special in MicroPython, in the sense that when you power-on the device and/or press the reset button, the contents of the {{main.py}} file are passed to the MicroPython interpreter and the program contained within main.py is executed. It's the ''entry point'' for running any application in Python.
At line 8 changed 2 lines
%%python
\\# this is a comment
%%python \\# this is a comment
At line 12 changed one line
print("hello again.")
print("hello again.") # you can use single or double quotes
At line 15 removed one line
There is a structure in Python called a {{try-except-finally}} __block__, which is ideal for a main.py file:
At line 17 changed 3 lines
%%filename main.py %%
%%python
\\# this is a comment
__See also:__ [The REPL|MicroPythonTutorialTheREPL]
At line 21 removed 11 lines
try:
print('hello world.')
^^^^ 🠈 remember to indent the insides of your blocks by 4 characters!
except Exception as ex:
print('an error occurred: {}'.format(ex))
finally:
print('complete.')
%%
At line 33 changed one line
__Previous:__ [MicroPython Tutorial Exercise 1|MicroPythonTutorialExercise01]: main.py \\
__Previous:__ [MicroPython Tutorial|MicroPythonTutorial]: home page \\