Python and MicroPython compatibility
Python and MicroPython compatibility
I’m porting a library from MicroPython to Python. Is there a programmatic way to determine if the code is running in MicroPython or Python? My code has a lot of const() definitions. Is there a strategy to improve compatibility so I don’t have to redo all the const() statements?
Re: Python and MicroPython compatibility
you could use:
const = lambda x:x
to avoid re-doing const statements. and you can query like:
if sys.implementation.name == "micropython":
......
to implement variants.
const = lambda x:x
to avoid re-doing const statements. and you can query like:
if sys.implementation.name == "micropython":
......
to implement variants.
Re: Python and MicroPython compatibility
Thanks, that's very helpful. Would you use the same approach to handle different I2C implementations?
Re: Python and MicroPython compatibility
You can bundle functions with differ in separate modules and import either of them, depending on the python version.