hi,
i want to run a script directly from booting the device,
when i make a file main.py it runs it straight from boot,
but when i make a folder main.py with my file as a subdirectory it doesnt,
can you run subdirectories in main.py or can you only run it as a single file?
booting main.py
Re: booting main.py
You can place all your files in the root directory of the board file system.
You can also place your library into the "lib" subfolder.
A third option is to create a sub-directory say "mydir" and then, you can append the "mydir" entry into the sys.path list.
Place your starting code inside a file named "mymain.py" inside the "mydir" folder. From "main.py" you wil be able to write "import mymain.py" and your software will be imported from "mydir" (as available in the sys.path) and executed.
PS: I don't know if sys.path can be modified directly from boot.py but it should be possible.
Cheers,
Dominique
You can also place your library into the "lib" subfolder.
A third option is to create a sub-directory say "mydir" and then, you can append the "mydir" entry into the sys.path list.
Place your starting code inside a file named "mymain.py" inside the "mydir" folder. From "main.py" you wil be able to write "import mymain.py" and your software will be imported from "mydir" (as available in the sys.path) and executed.
PS: I don't know if sys.path can be modified directly from boot.py but it should be possible.
Cheers,
Dominique
Re: booting main.py
this is the code from the main.py folder
so i went for the third option,
i must say it took a while but i learned alot in my search
i created a folder named 'mydir'
and put 2 files in it: 'mymain.py' and '__init__.py'
the last one so it would recognize the 'mydir' folder as a module.
tnx dominique, youre awesome!!!
btw is this the best way to implement it? i just put some code togheter from different sites and tried to make something work
Code: Select all
import sys
sys.path
sys.path.insert(0,'/mydir/mymain.py')
print (sys.path.insert)
from mydir import mymain
i must say it took a while but i learned alot in my search
i created a folder named 'mydir'
and put 2 files in it: 'mymain.py' and '__init__.py'
the last one so it would recognize the 'mydir' folder as a module.
tnx dominique, youre awesome!!!
btw is this the best way to implement it? i just put some code togheter from different sites and tried to make something work
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: booting main.py
You might also want to look up "Python packages" in any tutorial to learn more about using subdirectories to contain Python code.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: booting main.py
i will look into it, tnx for the info! ;
i ordered this book, i hope it wil be any good Advanced Programming in MicroPython By Example by magda yuri
and a small bookbinding machine, so i can print out stuff from the internet and keep it tighty
i ordered this book, i hope it wil be any good Advanced Programming in MicroPython By Example by magda yuri
and a small bookbinding machine, so i can print out stuff from the internet and keep it tighty
Re: booting main.py
Can I fix this on my own or should I know the basics of programming?
The best way to choose the best lender service? Always compare the proposals of the different banks with each other! Only in this way can you find the cheapest deal in your state, with your level of income, and for the time period that feels comfortable for you. Many here stress the improtance of finding the best rate, but there are situations when you cannot really choose and honestly, many people looking for a payday loan are in no position to choose. Some of them have low income to show for themselves, others have bad credit history, we all have financial problems from time to time. My advice is, do look around, visit a couple of websites with the rates compared, but do not forget that it is but a short term loan. Take it out, use it, and focus on improving your budget planning to never need a loan again. Good luck!
The best way to choose the best lender service? Always compare the proposals of the different banks with each other! Only in this way can you find the cheapest deal in your state, with your level of income, and for the time period that feels comfortable for you. Many here stress the improtance of finding the best rate, but there are situations when you cannot really choose and honestly, many people looking for a payday loan are in no position to choose. Some of them have low income to show for themselves, others have bad credit history, we all have financial problems from time to time. My advice is, do look around, visit a couple of websites with the rates compared, but do not forget that it is but a short term loan. Take it out, use it, and focus on improving your budget planning to never need a loan again. Good luck!