Skip to content

Commit f03f77b

Browse files
committed
Update tutorial to reference importing from modules on the file system.
1 parent c084920 commit f03f77b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/tutorials/storage.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@ for something to do. However, if you copy a special file called ``main.py``
219219
onto the file system, upon restarting the device, MicroPython will run the
220220
contents of the ``main.py`` file.
221221

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+
222240
.. note::
223241
If you have flashed a script onto the device in addition to the MicroPython
224242
runtime, then MicroPython will ignore ``main.py`` and run your embedded

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy