Tab Error in Python

前端 未结 4 623
故里飘歌
故里飘歌 2020-12-07 05:01

The following python code throws this error message, and I can\'t tell why, my tabs seem to be in line:

File \"test.py\", line 12
    pass
       ^ TabError         


        
相关标签:
4条回答
  • 2020-12-07 05:39

    not using the backspace also is important (especially in the Leafpad editor). If you want to decrease indent, use only Alt_key + TAB.

    This should be done when you delete a line in a Python code.

    0 讨论(0)
  • 2020-12-07 05:43

    open your code in a text editor, highlight all of it (ctr+a) and go to format and select either "Tabify region" or "Untabify region". It'll just make all the indents have the same format.

    0 讨论(0)
  • 2020-12-07 05:46

    You cannot mix tabs and spaces, according the PEP8 styleguide:

    Spaces are the preferred indentation method.

    Tabs should be used solely to remain consistent with code that is already indented with tabs.

    Python 3 disallows mixing the use of tabs and spaces for indentation.

    Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.

    When invoking the Python 2 command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

    0 讨论(0)
  • 2020-12-07 05:59

    Using Visual Studio 2019

    I was using tabs but the editor was inserting spaces and it would result in errors.

    To avoid getting the spaces and tabs mixed up , set your preferences

    Go to Edit->Advanced->Set Leading Whitespace->Tabs (or Whitespaces)

    After I set it to Tabs, my tabs stop being represented as spaces and it worked fine thereafter

    0 讨论(0)
提交回复
热议问题