【问题标题】:TabError: inconsistent use of tabs and spaces in indentationTabError:缩进中制表符和空格的使用不一致
【发布时间】:2015-08-28 16:55:24
【问题描述】:

文件“F:\Documents and Settings\Administrateur\cracker.py”,第 56 行 if line.startswith('

  • 我的代码:

    if system() == 'Linux':
      banner()
      f = open('/tmp/data.txt', 'rU')
      for line in f:
        if line.startswith('<li><a') == True:
          m = re.search(r'(<a href=")(.+[^>])(">)', line)
          i += 1
          local_name = '%s/file%d.txt' % (fout, i)
          print 'Retrieving...\t\t', site + m.group(2)
          try:  urllib.urlretrieve(site + m.group(2), local_name)
          except IOError:
            print '\n[%s] doesn\'t exist, create it first' % fout
            sys.exit()
        if line.startswith('<img') == True:
          m1 = re.search(r'(<a href=")(.+[^>])(">)', line)
          i += 1
          local_name = '%s/file%d.txt' % (fout, i)
          print 'Retrieving...\t\t', site + m1.group(2)
          try:  urllib.urlretrieve(site + m1.group(2), local_name)
          except IOError:
            print '\n[%s] doesn\'t exist, create it first' % fout
            sys.exit()
    
  • 【问题讨论】:

    • 您所要做的就是重新格式化您的代码,使其在整个文件中保持一致
    • 这正是错误所说的。使用您选择的编辑器来使用所有制表符或所有空格。
    • 文件 "F:\Documents and Settings\Administrateur\cracker.py", 第 56 行 if line.startswith('
  • @MEhdiMEhdi 我们知道错误并告诉您如何修复它
  • 标签: python


    【解决方案1】:

    或者每个缩进使用 4 个空格,或者每个缩进使用一个制表符(每个制表符的空格很可能在您的编辑器中设置)。不允许混合制表符和空格。您可以手动解决此问题(通过检查并重新缩进所有内容),或者您的编辑器很可能有一个工具可以为您解决此问题。

    【讨论】:

    • @MEhdiMEhdi 不要要求我们为您编写代码。你为什么不根据这个答案进行更正?
    • 更正码?上面多次给出了解决方案:您的代码格式不正确。你用的是什么编辑器?
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签