“inconsistent use of tabs and spaces in indentation”

后端 未结 28 2229
北恋
北恋 2020-11-22 00:56

I\'m trying to create an application in Python 3.2 and I use tabs all the time for indentation, but even the editor changes some of them into spaces and then print out \"inc

相关标签:
28条回答
  • 2020-11-22 01:15

    When using the sublime text editor, I was able to select the segment of my code that was giving me the inconsistent use of tabs and spaces in indentation error and select:

    view > indentation > convert indentation to spaces

    which resolved the issue for me.

    0 讨论(0)
  • 2020-11-22 01:15

    Use, Idle for python, or Idle3 for python3.

    0 讨论(0)
  • 2020-11-22 01:16

    I had this problem. Solution: your 'tab' before the problem line is spaces, 4, 6, or 8 spaces. You should erase them and insert TAB. '\t'. That's all.

    0 讨论(0)
  • 2020-11-22 01:17

    It is possible to solve this problem using notepad++ by replacing Tabs with 4 Spaces:

    1. Choose Search -> Find... or press Ctrl + F
    2. Select the Replace tab
    3. In the box named Search Mode choose Extended(\n, \r, \t, \0, \x...)
    4. In the field Find what : write \t
    5. In the field Replace with : press Space 4 times. Be sure that there is nothing else in this field.
    6. Click on the button Replace All

    0 讨论(0)
  • 2020-11-22 01:17

    If your editor doesn't recognize tabs when doing a search and replace (like SciTE), you can paste the code into Word and search using Ctr-H and ^t which finds the tabs which then can be replace with 4 spaces.

    0 讨论(0)
  • 2020-11-22 01:18

    I recently had the same problem and found out that I just needed to convert the .py file's charset to UTF-8 as that's the set Python 3 uses.

    BTW, I used 4-space tabs all the time, so the problem wasn't caused by them.

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