Page 1 of 1

How to import my driver(e.g private ".py" file)

Posted: Thu Apr 30, 2020 1:54 am
by lc2047
Hi

With python(PC ver.), we can split something(e.g. function, diver, or data) in a separate file. And import it when using it.
Shell we do that in micropython?

However, the system(not sure in IDE or board) seem to accept ONE file(main.py or main.hex) only.

If not possible, the script file(main.py) will be very big and difficult to read.

I saw some 3rd party provide their library in ".hex". This style like a ".dll" in PC system. Do we have another way to except this method?

Please share your experience/ comment.


Thanks

Re: How to import my driver(e.g private ".py" file)

Posted: Thu Apr 30, 2020 1:19 pm
by T-Wilko
Hi there,

You are correct in your observation that MicroPython reads main.py, but it actually reads a boot.py before that as well.

To import a driver file (e.g. 'driver.py' that you have uploaded to the board's flash already) you do exactly what you do in Python and simply

Code: Select all

import driver
and from there you can utilise classes/functions/variables that exist in that .py file.

I personally haven't dealt with any hex file in relation to MicroPython so I'm afraid I'm of no assistance there, although I don't think there's any relation there to MicroPython drivers.

Re: How to import my driver(e.g private ".py" file)

Posted: Thu May 07, 2020 2:00 am
by lc2047
Hi @T-Wilko

Thanks for your share.

Re: How to import my driver(e.g private ".py" file)

Posted: Wed May 20, 2020 4:36 am
by jimmo
lc2047 wrote:
Thu Apr 30, 2020 1:54 am
However, the system(not sure in IDE or board) seem to accept ONE file(main.py or main.hex) only.
Which board are you using? .hex file suggests maybe micro:bit ?