[Microbit-Python] User modules?

M.-A. Lemburg mal at egenix.com
Fri Feb 26 04:37:01 EST 2016


On 25.02.2016 20:33, Christopher Arndt wrote:
> Is there any possibility to modularize MicroPython code for the micro:bit?
> 
> Since there isn't a flash file system, I guess there's no way to store
> user modules. Or is there a way to embed additional modules into the
> firmware?

We had discussed this a few weeks ago. It should be possible
to the uflash tool to combine several modules into one and
then playing a few tricks to get the namespaces right.

MicroPython appears to be using classes for the module namespaces,
so putting the code into a class wrapper appears to be a good
solution for the namespaces:

>>> import music
>>> type(music)
<class 'module'>

All that said, I don't know how much flash memory is available
for Python scripts, and of course, the memory constraints don't
allow for many code objects to exist anyway. The 32kB retail
version of the MB should reduce the latter problem a bit.

Perhaps Cython could be used to compile Python modules into
C and then have those added to the firmware when flashing the
MB. That should reduce the code object overhead.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Feb 26 2016)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________
2016-02-19: Released eGenix PyRun 2.1.2 ...       http://egenix.com/go88

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/



More information about the Microbit mailing list