Syntax error in Python script run: Indentationerror:unindent does not match any outer indentation level

Source: Internet
Author: User
Tags python script

Problem
A python script, which would have run well, then wrote a few lines of code, and also ensured that each line was aligned, but when it ran, there was a syntax error:
Indentationerror:unindent does not match no outer indentation level

"Resolution Process"
1. The most common reason for this error is that there is indeed no alignment. But I'm going to look at the code based on the number of lines I've been wrong.
All with the TAB key, aligned well, there is no misaligned line number AH.
2. Think that the contents of the previous comment affect the syntax of the following statement, so the previous comment has also been deleted.
The result is still this syntax error.
3. After a long day of tossing, suddenly thought of, the current Python script all the characters are displayed to see if there are any special characters.

The currently used text editor notepad++, as if there is a setting that can display all the characters.
Found, in:
Show spaces and tabs, display symbols, view

Then you can see the problem:
The original error line number is 1580 rows:

But the source of the 1580 lines of the alignment with a dot point of space, and the previous lines of the alignment of the arrows used to indicate the TAB key, is mismatched, that is, the code alignment, mixed with the TAB key and space:


The new Python syntax, which is not supported by code alignment, is mixed with tab and space. So the above error message appears.

Knowing the reason, the solution is simple:
To the corresponding tab, are changed to a space, unified the style of alignment, you can.
In the notepad++, go:
Preferences, Settings:

Language--Replace with a Space (Tab key):

Can be implemented, for each subsequent tab input, are automatically converted to 4 spaces.

Summary

Python encountered Indentationerror, the first time to think, is not due to the TAB key and the use of space mix.

It is estimated that many people are also responsible for this kind of cause. Just remember to unify a bit.

Blog Original address: http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/

Syntax error in Python script run: Indentationerror:unindent does not match any outer indentation level (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.