Closed Bakkom closed 3 years ago
What kind of problem did you get? Could you copy/paste the exact error message?
The code example here is correct, these things are more or less equivalent:
import microbit
microbit.display.show(microbit.Image.HAPPY)
from microbit import *
display.show(Image.HAPPY)
from microbit import display, Image
display.show(Image.HAPPY)
The main difference here is that the second option imports everything inside microbit
into the current scope (so accelerometer
, compass
, etc are also available without doing something like microbit.compass
) and the last option only imports display and Image.
If I run a microbit.example on a Micro:Bit it returns "NameError, Name "microbit" not defined" or something of the likes. This is also the case for "import microbit". "from microbit import example" is the only way I can import to the Micro:Bit
How did you flash MicroPython into the micro:bit board? import microbit
should definitely work.
I don't know, someone else did it, but I'll flash it again then. I'm sorry. I was 100% sure the documentation was off since I'm running a python program on it flashed from the MicroPython IDE.
No worries, if you've encountered this issue it's likely somebody else might in the future as well, so we really appreciate reporting these things and any contributions are always greatly welcomed!
Were you using https://python.microbit.org or the Mu editor? or something else?
https://python.microbit.org What wasn't working was everything related to "microbit.example", but if I imported "from microbit import *", and dropped the "microbit."-prefix, everything was working beautifully.
Could you try again? This is what I currently get from the online Python Editor REPL after flashing a programme:
MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit v1.0.1 with nRF51822
Type "help()" for more information.
>>> import microbit
>>> microbit.display.show(microbit.Image.HAPPY)
>>>
And works as expected.
OK. I guess you are magic because now everything is working? Thank you.
🧙 In that case I'll close this PR. Thank you testing again and debugging through this.
A non-existing function named "microbit" was causing a NameError. Changed [Import microbit] to [from microbit import *]. NB! "dir(microbit)" is still making a NameError, since microbit isn't defined or a pre-existing function. I am not sure what this line is meant to do, so I've let it be.