“inconsistent use of tabs and spaces in indentation”

后端 未结 28 2232
北恋
北恋 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:37

    Your problem is due to your editor limitations/configuration. Some editors provide you of tools to help with the problem by:

    1. Converting tabs into spaces

      For example, if you are using Stani's Python editor you can configure it to do it on saving.

    2. Converting spaces into tabs

    If you are using ActiveState Komodo you have a tool to 'tabify' your code. As others already pointed, this is not a good idea.

    Eclipse's Pydev provides functions "Convert tabs to space-tabs" and "Convert space-tabs to tabs".

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

    If you use ATOM:

    Go to Menu: Packages --> WhiteSpace --> Convert all Tabs to Spaces

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

    Generally, people prefer indenting with space. It's more consistent across editors, resulting in fewer mismatches of this sort. However, you are allowed to indent with tab. It's your choice; however, you should be aware that the standard of 8 spaces per tab is a bit wide.

    Concerning your issue, most probably, your editor messed up. To convert tab to space is really editor-dependent.

    On Emacs, for example, you can call the method 'untabify'.

    On command line, you can use a sed line (adapt the number of spaces to whatever pleases you):

       sed -e 's;\t;       ;' < yourFile.py > yourNedFile.py
    
    0 讨论(0)
  • 2020-11-22 01:41

    Try deleting the indents and then systematically either pressing tab or pressing space 4 times. This usually happens to me when I have an indent using the tab key and then use the space key in the next line.

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