Daily tips and tricks from the experts at Adafruit!
View this email in your browser

If you’re coming to MicroPython or CircuitPython with a background in Python programming you might wonder, what are the differences between MicroPython and desktop Python (or CPython)?  MicroPython attempts to implement all of the core Python 3.x language but it turns out there are a few small differences and features that don’t work the same between MicroPython and CPython.  Check out this excellent page from MicroPython’s documentation which explores the features of MicroPython that differ with CPython.

If you look at the differences you’ll be happy to see most are for uncommon or odd edge cases of Python usage.  Two things that might trip you up though are these differences in Python classes:

  • The __del__ function for a class is not supported by MicroPython.  Typically you use the __del__ function to perform cleanup or run code when an object has been deleted and the garbage collector reclaims its memory.  In MicroPython this is not supported so you’ll want to explicitly perform cleanup, perhaps by adding a cleanup function you call yourself.
  • When using multiple inheritance the super() function only calls one parent class initializer.  It’s not very common however to use multiple inheritance and if you feel a need for it consider changing your class design to use composition instead of inheritance.

Don’t forget either MicroPython doesn’t implement all of the Python standard library, instead there are MicroPython-specific versions of some Python standard library modules.  These MicroPython modules are typically much smaller and just implement some core functionality.  With embedded systems it’s always a tradeoff of functionality and available memory!