[Microbit-Python] importing modules using uflash

Radomir Dopieralski microbit at sheep.art.pl
Wed Sep 14 15:55:28 EDT 2016


It just uses normal python commands, such as open(), file.read(),
file.write(), os.listdir() and so on, but executes them over the REPL
console. You can see exactly what it does here:
https://github.com/ntoll/mu/blob/master/mu/contrib/microfs.py

On Wed, 14 Sep 2016 21:15:22 +0200
"M.-A. Lemburg" <mal at egenix.com> wrote:

> On 11.09.2016 14:00, Radomir Dopieralski wrote:
> > 
> > Not quite.
> > 
> > It doesn't matter how you upload your main script -- you can use
> > uFlash or Mu or the online editor, or even prepare the hex file
> > yourself by hand. The thing is, that the hex file can contain only
> > one python file in it.
> > 
> > However, there is also internal filesystem on the micro:bit, where
> > you can put additional files to be imported by your main script.
> > The most convenient way to access that filesystem and upload your
> > files is by using the latest version of the Mu editor. Of course,
> > you could as well just write a program that creates the file and
> > writes its contents, but that is a little roundabout way of doing
> > it.
> > 
> > I hope this helps.
> 
> Is the functionality needed for uploading modules to the
> MB documented somewhere ? (A pointer to the right place
> in the Mu editor code would already help :-))
> 
> Background: I've been looking for something like a few months
> ago and back then, there was no filesystem module import for
> the MB.
> 
> Thanks.
> 
> > On Sun, 11 Sep 2016 12:47:20 +0100
> > "hot.toast via Microbit" <microbit at python.org> wrote:
> > 
> >> So as i understand it,
> >>
> >> 1. uFlash is limited to python scripts that contain all the local 
> >> function and class definitions. The only imports that are allowed
> >> are those from the microbit version of micropython.
> >>
> >> 2. If I want to import  "mymodule.py" from a file on my local hard 
> >> drive, I will have to use the latest version of the mu editor...
> >>
> >> On 11/09/16 12:19, David Whale wrote:
> >>> Make sure you use the most up to date version of Mu though to do
> >>> this, as it was a feature that was added reasonably recently. The
> >>> version of Mu in the Raspberry Pi repo's is still out of date at
> >>> the moment, and might not have this feature included yet.
> > 
> > 
> 



-- 
Radomir Dopieralski

-- 
Radomir Dopieralski


More information about the Microbit mailing list