In this lecture can show you how to install an external module so that you can use it with your micro
python protection, SB 32.
In this case.
In this example, I'm going to use awesome micro python to look for an interesting module.
And there's quite a lot here.
But one that drew my attention is this one here.
Micro math, micro mathematics and analytics looks interesting.
So click on the link here that will take you to the repository for this particular project.
Now, this is a GitHub project and the files are up the top with a description of the project down the
bottom.
So there's a wiki as well.
I can see issues and documentation page.
Let's have a look at those to see what's happening here.
Just click there.
So the wiki doesn't have much just a list of to do items here.
They could have a documentation.
I can take you back to the same GitHub main page.
So not much there either.
But we do have access to the source code so we can drill inside the source code.
The math directory contains a bunch of python files.
You can browse these files to see what this project is all about.
In many cases with micro python projects, the source code itself is the limitation you can find.
So we have a look inside.
Operator, operator, Dopy why has a few simple functions for additional application, power calculations,
etc..
Let's compare it to a look at another one, maybe inside calculus.
So it looks like this is populated with calculus related functions.
OK, it's a few to do items here as well.
But for the sake of this example, this is actually good to go.
So to install it, the first thing to do is to download a zip version of this archive.
So click on the green button, then click on Download Zib that will bring the zip file onto your computer.
And in my case I have already downloaded it and expanded it from the zip file so that this is now the
contents of the repository on my computer.
Now the thing that you need is the math.
That victory, very often a module will contain a single file.
But in some cases, like in this case here, the module comes as a collection of files usually bundled
inside a directory.
So the next thing to do is to get this directory over to a folder that I can use in order to upload
from that folder to my HP through to the server.
Look at 30.
So 30 has got the file step here.
And right now I've browsed into Micro Python E.S.P 32 two, which is sitting on my desktop so I can
either redirect this over to my downloads folder in order to be able to see the math directory inside
this list of files and directories.
Or in this particular case, I'm just going to copy.
This directory and pasted inside.
My open directory, I'm just going to come wait and paste it over, so it's a very standard and move
to the top now.
So there is my UMass directory right there inside my micro python, especially two, and it's cruel.
And yet they just appeared now in my list of files and the phony.
Right there.
And the next thing to do to be able to use it on my experience is to transfer the whole directorate
into my especially to flash memory and system.
So the easiest way to do that is to.
Right.
Click on the director or the TransFair and then select upload forward slash.
Do that.
Wait for a few seconds.
And there's math, right?
So I'm going to do a couple of experiments.
To try out the contents of this module, just trying to expand the shelf part of the window so you can
see more what's happening.
Of course, remember, you always have the source code.
Let's say that you want to play around with the functions inside operator Torpy.
So just double click on Operator to provide to see what's inside.
And you see the three or four functions that are available here.
And the first thing that you want to do is to import the module into your show so that you can use it.
So the easiest way to do that is to say that you want to use the new math module, but specifically
you want to import operator.
So if you just say import your math, then you'll be importing all of the files that are part of the
you must directory, but if you only want to use the functions inside the operator file, then you can
say from your mouth the name of the directory import operator, the name of the file without the extension.
So enter and now we can use the ADD function in this way, so two, three has those two numbers across
and the addition is five.
What about Peter W. Power?
Two in the power of three is eight and so on.
You can subtract.
And it works now in the exact same way as what you've just seen me doing on the show, they can use
the exact same method to import a library file or a module file to your ISP.
Three to one more thing that I want to show you before we close with this lecture, and this section
is to show you what you can do if you only really need one of those files, you don't need all of them.
They may not be taking RAM if you have an import them, but they are taking up precious flash memory
space.
So maybe you don't want all of them.
But let's say that you only want the operator functions.
So let's clean up here and remove the directory from my device.
I can then go to operate on just the single file that I want to store on my micro python device and
upload it.
And that appears here on the same level as the rest of my files, it's not inside a directory this time
around, just going to do actually a soft actually up to a reset in order to reboot essentially my ISP
three, two and clear memory.
All right.
So starting from fresh new, I want to import operator, so just say the import operator.
And now I can use the functions that come with operator and the look inside the file again, just like
before you could say operator, add two and three together and that will give us five.
So there's a couple of of ways by which you can do that, but virtually with every single case you'll
be able to use this methodology to import a module to your ability to be able to use on the show or
through Python filed.