Can't find pins class

Trying to read an analog voltage on either pin 0, 1, or 2. Can do this in MakeCode but want to do it in Python instead. When I do it in MakeCode, and then I switch the editor to get the equivalent Python code, that code looks like this:

def on_forever():

When I paste that code into the Python editor, it can’t find ‘basic’ or ‘pins’. I’m assuming those are needed imports but I can’t figure out how to resolve that problem.


Are you pasting it into the MakeCode Python editor or the Python-only editor, like this one: ?

The Python-only editor uses a different version of Python than MakeCode. You can read about the differences between the two types of Python here:

The different version, called MicroPython, has different names for the commands, which are described here: In the Python-only (MicroPython) version it would look like this:

from microbit import *

while True:

Thanks I’ll try!

It’s really not clear which Python context I’m in. How does one determine this from the navigation / GUI?


Hi @bethesda,

The MakeCode Python code only works in MakeCode. If you are pasting the code into anyplace else, it’s probably expecting the MicroPython approach. That is, any place other than is probably MicroPython and you need to use the approaches described here: .

If you are using the MicroPython approach, the current micro:bit on-line Python editor works great! It’s at . Here’s a very brief overview (thanks to Kitronic):