How to fix Python indentation

前端 未结 13 1304
梦毁少年i
梦毁少年i 2020-11-22 08:17

I have some Python code that have inconsistent indentation. There is a lot of mixture of tabs and spaces to make the matter even worse, and even space indentation is not pre

相关标签:
13条回答
  • 2020-11-22 08:59

    I have a simple solution for this problem. You can first type ":retab" and then ":retab!", then everything would be fine

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

    There is also PythonTidy (since you said you like HTML Tidy).

    It can do a lot more than just clean up tabs though. If you like that type of thing, it's worth a look.

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

    In case of trying to find tool to make your 2-space indented python script to a tab indented version, just use this online tool:

    https://www.tutorialspoint.com/online_python_formatter.htm

    0 讨论(0)
  • 2020-11-22 09:05

    Try Emacs. It has good support for indentation needed in Python. Please check this link http://python.about.com/b/2007/09/24/emacs-tips-for-python-programmers.htm

    0 讨论(0)
  • 2020-11-22 09:06

    If you're lazy (like me), you can also download a trial version of Wingware Python IDE, which has an auto-fix tool for messed up indentation. It works pretty well. http://www.wingware.com/

    0 讨论(0)
  • 2020-11-22 09:08

    Using Vim, it shouldn't be more involved than hitting Esc, and then typing...

    :%s/\t/    /g
    

    ...on the file you want to change. That will convert all tabs to four spaces. If you have inconsistent spacing as well, then that will be more difficult.

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