Python 期望 Sublime Text 3 上有一个缩进块[重复]

问题描述 投票:0回答:3

这是一个更大代码的示例摘录,我不知道为什么没有正确识别

代码示例:

if True:
    for i in range(1, 10):
        print(i)
    print("Inside the if")
    print("But outside the loop")

实际代码:

def mkfolder(self):
    path = self.edit_dir.text()
    prefix,fromn,ton,formatn
    if not os.path.isdir(path):
        return self.showerror("Erro de parâmetro", "Caminho para criar as pastas é inválido ou não existe\nCód.: 0052")
    if not self.chk_prefix.isChecked():
        prefix = ""
    else:
        prefix = self.edit_prefix.text()    
    if self.chk_count.isChecked():
        fromn = self.spin_from.getValue()
        ton = self.spin_to.getValue()
        formatn = self.spin_format.getValue()
        if ton <= fromn:
            return self.showerror("Erro de parâmetro", "Não é possível fazer uma contagem regressiva\nCód.: 0010")
        if len(str(abs(ton))) < formatn:
            return self.showerror("Erro de parâmetro", "Quantidade de dígitos é insuficiente\nCód.: 0012")
        strFormat = "{0:0>"+ str(formatn) +"}"
        msg = self.askquestion("Aviso", str(ton - fromn) + " pastas\n Em " + path + "\n De '" + prefix + strFormat.format(fromn) + "'\na '"+ pref+ strFormat.format(ton) +"'\n\nConfirma?")
        if msg==22:

            for i in range(fromn, ton+1):
                os.makedirs(path + "/"+ prefix + strFormat.format(i))           
            self.tomain()
            self.mkclean()
python python-2.7 sublimetext3
3个回答
0
投票

它的缩进不正确,因为您混合了制表符和空格。不要那样做。 Python 不喜欢你这样做。每次你这样做,小狗就会哭


0
投票

很有可能,您的制表符和空格不一致。一些文本编辑器具有特殊的“制表符”来添加间距,而其他文本编辑器只是将制表符转换为多个“空格字符”。我建议研究如何在文本编辑器中显示非打印字符,以查看哪些行是间隔的,哪些是制表符的。


0
投票

这个工具可能会派上用场来检查 Python 中的缩进

https://pythoniter.appspot.com/

附加:让你的代码看起来很专业

http://pep8online.com/

© www.soinside.com 2019 - 2024. All rights reserved.