“inconsistent use of tabs and spaces in indentation”

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

    I had the same problem and fix it using following python script. hope it help others.

    it is because of using tabs and spaces for indenting code. in this script I replace each tab with four spaces.

    input_file = "source code path here"  # e.g. source.py
    output_file = "out put file path here"  # e.g out.py
    with open(input_file, 'r') as source:
        with open(output_file, 'a+') as result:
            for line in source:
                line = line.replace('\t', '    ')
                result.write(line)
    

    if you use sublime or any other editor which gives you the tool to replace text you can replace all tabs by four spaces from editor.

提交回复
热议问题