Sometimes your code can get so complex that putting it into a single file doesn't make sense. In these cases you can break code into multiple files and create a Python package that puts all the code together into what looks like a simple module your scripts can import. MicroPython supports the concept of Python packages just like normal Python so you can better structure complex scripts.
+
+
First be sure to read the [https://docs.python.org/3/tutorial/modules.html#packages official documentation on Python packages]. Packages in MicroPython for the most part work just the same as in Python.
+
+
Now create a Python package on your computer by creating a directory called '''test'''. Inside that directory create a file called '''add.py''' and place inside it the add function code:
+
+
<syntaxhighlight lang="python">
+
def add(a, b):
+
return a + b
+
</syntaxhighlight>
+
+
Create a file '''subtract.py''' in the same location and place in it the subtract function code: