File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,24 @@ for something to do. However, if you copy a special file called ``main.py``
219
219
onto the file system, upon restarting the device, MicroPython will run the
220
220
contents of the ``main.py `` file.
221
221
222
+ Furthermore, if you copy other Python files onto the file system then you can
223
+ ``import `` them as you would any other Python module. For example, if you had
224
+ a ``hello.py `` file that contained the following simple code::
225
+
226
+ def say_hello(name="World"):
227
+ return "Hello, {}!".format(name)
228
+
229
+ ...you could import and use the ``say_hello `` function like this::
230
+
231
+ from microbit import display
232
+ from hello import say_hello
233
+
234
+ display.scroll(say_hello())
235
+
236
+ Of course, it results in the text "Hello, World!" scrolling across the
237
+ display. The important point is that such an example is split between two
238
+ Python modules and the ``import `` statement is used to share code.
239
+
222
240
.. note ::
223
241
If you have flashed a script onto the device in addition to the MicroPython
224
242
runtime, then MicroPython will ignore ``main.py `` and run your embedded
You can’t perform that action at this time.
0 commit comments