How to import my own module into a project?
-
Hello. I'm new to m5stack. I have a possibly simple question. how to import my own modules in a project? in block or python modes?
-
Hi @Alexander ,
First you may need create your module file(like myModules.py) on UIFlow,and create some block for your modules.
Then make some block for your modules.
Make some blocks on this workspace.
When you are finished, you can click the download button in the lower right corner, and then open the downloaded m5b file in UIFlow.
-
Thank you.
-
I have a file.py. There are 20 custom functions in the file. This is a lot of code. Many of the functions call each other in calculations.
In any new M5flow project, I just want to write "import file" first. And that's all.
I don't want to rewrite all the functions separately for the M5flow. Or insert all this code into each new project manually. Or create blocks for each function.
I saved the file to the device manager file. But still importing the file doesn't work.
It seemed to me that there should be a simple and obvious solution. This is all very strange.
maybe I just need to save the file in the appropriate format in the appropriate directory Uim5flow installed on the pc? -
@alexander you have to store it on the M5stack in the directory where the main.py file is located and use it with python code in execute blocks.
-
@gaviota I'm trying to. But M5stack:"ERROR no module named"
Until I understand what is wrong. -
@alexander try visual studio code (vscode) to import your module in the directory where you can find also the file main.py. Tutorials for using m5stack with vscode are located on the m5stack-youtoube-channel https://www.youtube.com/channel/UCozgFVglWYQXbvTmGyS739w e.g. this video: https://www.youtube.com/watch?v=Y9pOWgsNgKk
-
@gaviota Well thank you.
I'm tired of my own inability to solve this problem. So far, I just threw all the functions into the project.
Later I will do so, as you advise. -
Ok it's an old one but as I've found a solution...
1- Write your function code in test_code1.py for example, with a function dazi() inside.
2- Write your program code and on the top :
from apps import test_code1
3- when you want to use your dazi function, write then test_code1.dazi('.........../......')It's working for me.