You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following real world example from a novice:
# Imports go at the topfrommicrobitimport*LED_Pin=pin0#at the start of each cycle we turn off all the LEDs, so make a function for it.defLED_AllOff():
LED_Pin.write_digital(0)
#indicate we are running by turning on the LEDLED_Pin=Truesleep(500)
whileTrue:
LED_AllOff()
#todo add some sensing and display heresleep(1000)
To make the code readable the novice has defined LED_Pin as a nice alias for Pin 0 (there is an LED connected to it)
They are constructing a piece of code that will have multiple LEDs indicating 'stuff', so have defined a function to turn off all of them.
Then they forget they have to call 'write_digital' to access the pin and try to set the pin to True - to turn it on.
Python accepts this as a fine and beautiful line of code....
In the while loop they plan to turn off all the LEDs and then sense the temperature, before turning on the appropriate one.
They get a not helpful error message on the line:
LED_Pin.write_digital(0)
which is caused by their slip on a later line and python dynamically retyping the variable LED_Pin as a bool.
This is a 'feature' of python, fair enough, but it is a hard error to spot and the editor hasnt helped. (I have trimmed the code to just the minimum to illustrate - there was a lot more which made it more hidden).
Possibly indicating a variable has changed type in some way might help.
The text was updated successfully, but these errors were encountered:
Consider the following real world example from a novice:
To make the code readable the novice has defined LED_Pin as a nice alias for Pin 0 (there is an LED connected to it)
They are constructing a piece of code that will have multiple LEDs indicating 'stuff', so have defined a function to turn off all of them.
Then they forget they have to call 'write_digital' to access the pin and try to set the pin to True - to turn it on.
Python accepts this as a fine and beautiful line of code....
In the while loop they plan to turn off all the LEDs and then sense the temperature, before turning on the appropriate one.
They get a not helpful error message on the line:
which is caused by their slip on a later line and python dynamically retyping the variable LED_Pin as a bool.
This is a 'feature' of python, fair enough, but it is a hard error to spot and the editor hasnt helped. (I have trimmed the code to just the minimum to illustrate - there was a lot more which made it more hidden).
Possibly indicating a variable has changed type in some way might help.
The text was updated successfully, but these errors were encountered: