I am using Python 3 IDLE on all my computers. The indentation is 4 spaces whether you press TAB or Ctrl - ]. I noticed that MicroPython script needs the TAB character otherwise it will not understand indentation correctly. So are the 4-spaces tabs not recognized by MicroPython?
I have not found any way for IDLE to produce TAB characters so I'm using Npp for MicroPython scripts. It's a bit annoying. I like to test snippets of code on PC in IDLE and copy the snippets to MicroPython script for upload. I have to manually strip the spaces IDLE produces and replace with TAB characters in Npp.
Indentation character in a script
Re: Indentation character in a script
I use indentation by spaces throughout all editors, which works well with all Python variants. I set my editors to replace Tab by spaces. Maybe you can check with hd or similar which characters are really in your scripts.
Re: Indentation character in a script
I'll check again but my impression is only tab character works. Thanks.
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: Indentation character in a script
I use note++ to write all my micropython scripts and only use double space for indentation by pressing space bar twice.
Re: Indentation character in a script
Either this is a bug, or you are accidentally mixing tabs with spaces leading to visually correct indentation, which actually isn't correct. Can you give an example of code which can be used to reproduce this? As others said, MicroPython normally handles spaces just fine.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Indentation character in a script
MicroPython undoubtedly works with four spaces. It is the PEP8 Python coding standard.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Indentation character in a script
Quite possibly I mixed tabs with spaces. I carefully wrote a test program with only 4-space indentation. Works fine with 3 levels of indentation!stijn wrote: ↑Sat Apr 14, 2018 6:34 amEither this is a bug, or you are accidentally mixing tabs with spaces leading to visually correct indentation, which actually isn't correct. Can you give an example of code which can be used to reproduce this? As others said, MicroPython normally handles spaces just fine.
I feel relieved. It's just me again! I will see if I can make Npp do 4-space when I press tab key. Using Npp on an existing python script out of IDLE was probably the cause. Npp uses tab characters while IDLE uses 4-space.
Thanks as always.
[Edit]: There is a general setting in Npp to replace tab with spaces and language-specific setting.
Here is what I had to do:
Re: Indentation character in a script
Note if you use View->Show Symbol->Show White Space and TAB it will show the characters.
Also if you don't ever want to have problems like this again make the computer fix it for you, that is what computers are for, not the other way around. Most text editors can automatically turn tabs into spaces at save/load of a file. I don't use npp anymore but this should do it, for example: https://github.com/editorconfig/editorc ... -plus-plus.
Also if you don't ever want to have problems like this again make the computer fix it for you, that is what computers are for, not the other way around. Most text editors can automatically turn tabs into spaces at save/load of a file. I don't use npp anymore but this should do it, for example: https://github.com/editorconfig/editorc ... -plus-plus.