I am new to MP, starting with simple scripts on ESP32. I have learned that alignment of code is relevant in MP (loops, conditional statements). Are they any other rules? like spaces, empty lines, uppercase vs lower case, etc? I have been searching for mistake in my code and could not find it, but after deleting it and retyping it suddenly worked as expected. I suspect I had some unnecessary item (like space ) that was causing error as I retyped identical code.
Are they any user friendly editor that you can recommend that would highlight errors help to find them? I use notepad++ , it is quite helpful, but was not indicating any errors in my above attempt. Do you know any other editor that might help?
MP syntax error
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: MP syntax error
Python is very sensitive about indention as this is the way a block is defined compared to other languages that use brackets. Python is also case sensitive so True and true are seen as different.
Most people will use a good IDE to help with the formatting. I haven't yet learned to use any of the IDEs so I use Notee++ myself. I have found there can be formatting that you don't realize without looking at the left of the line of code for the status of each line. Make sure that you save the file with a .py ending then note++ knows it is a python file and will format it much better for you.
Most people will use a good IDE to help with the formatting. I haven't yet learned to use any of the IDEs so I use Notee++ myself. I have found there can be formatting that you don't realize without looking at the left of the line of code for the status of each line. Make sure that you save the file with a .py ending then note++ knows it is a python file and will format it much better for you.
Re: MP syntax error
Doesn't Notepad++ have pluging for Flake8/PyLint/Pep8 Autoformat etc? That will save you a lot of work.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MP syntax error
If you're new to Python I'd recommend starting with standard Python on a PC, and following a book or online tutorial. MicroPython is effectively identical until you get on to fairly advanced topics, and there are a number of PC IDE's available including debugger support. It also saves the hassle of copying files to the device.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: MP syntax error
I routinely use PyCharm community edition (which has a Micropython plugin) with Geany as a lightweight editor for casual browsing/editing when creating a full project in PyCharm is too much hassle. Other editors on my radar as high-quality but which I haven't used in anger are Mu Editor, VSCode, WingIDE (which has some free versions). Mostly I don't use these because of issues with Python3 debugger support, as I think they are all fine editors which should help you with managing indentation and syntax.