All know that Python is very strict in format requirements, wrote some python but did not find him strictly where, today encountered indentationerror:unexpected indent error I only know how strict he is.
After encountering the indentationerror:unexpected indent you need to know that the Python compiler is telling you "Hi, man, your file is not in the wrong format, it may be that the tab and space are not aligned, you have to check the tab and the space."
On Windows you can see with editplus, although I don't know how to show tab, but he can show that your files are misaligned, I wrote Python on Ubuntu. I use VIM, you can set the next vim in the tab with a space to replace, I wrote in the previous article about this setting problem, I now add, before is set in the system directory, and now I want to set in the home directory;
First CD ~ (to your home directory)
Then Ls-a (Show hidden files)
Find the. VIMRC (remember with a dot prefix)
Then edit this file
Locate the following command:
Set Autoindent
Set Smartindent
Set tabstop=4
Set shiftwidth=4
Set softtabstop=4
Set Noexpandtab
Then add the set expandtab in front of the set tabstop=4 and you need to put the set noexpandtab this comment off, how to annotate it, just add a double quotation mark. I have not tried direct annotations without set expandtab, I think it is possible (the default is Expandtab). This way you can rest assured of using VIM.
Of course, I do not want to do so, I actually want to see my code in the end where there is a problem, you need to look at his format, mainly to look at the tab, this can also be set in the file just now, in the following example
Add a set list below the set softtabstop=4. This will allow your vim to open the file to Show tab, of course, you may think that the display is not good to see, he showed the appearance of "^i" a number key 6 on the symbol and an uppercase I for a tab, this does not show a space. He will also show the starting character of the paragraph ^ and terminator $, if you do not know the 2 symbols can look at the regular expression.
After 2 points set, I think you will not encounter indentationerror:unexpected indent This is a very annoying mistake.
The set commands above can be used alone, but only for the currently open vim, you can press SHIFT plus colon, then enter set XXX, return and then have effect, but you have to enter the editing mode again to see.
Want to share with everyone who writes Python.
indentationerror:unexpected indent python