【问题标题】:PYTHON ERROR: IndentationError: unindent does not match any outer indentation level [duplicate]PYTHON ERROR:IndentationError:unindent 不匹配任何外部缩进级别[重复]
【发布时间】:2013-09-04 13:37:09
【问题描述】:

运行这段代码时:

#timestamp, capture, and tweet an image
def stamp_cap_tweet():    
    timestamp = time.strftime("%d%m%Y-%H%M%S")
    os.system("fswebcam -r 960x720 -d /dev/video0 " + timestamp + ".jpg") #save image to disk
    twit.update_status_with_media(timestamp + ".jpg", status = "@shahidrogers " + timestamp) #tweet image @username
    print "Tweeted image at " + timestamp #make a record in the Python output

我得到了错误

文件“tweetpicture.py”,第 17 行

os.system("fswebcam -r 960x720 -d /dev/video0 " + timestamp + ".jpg")                                                  
                                                                    ^                                                   IndentationError:

unindent 不匹配任何外部缩进级别

这可能意味着什么?我四处搜索,人们说有制表符和空格的混合,但我完全不明白这一点,因为我对 Python 还是很陌生,这是我的前几行编码。

谢谢!

【问题讨论】:

  • 只使用空格键重新缩进你的代码,看看会发生什么。
  • 为什么这个问题被否决了?它很清楚,显示了研究工作。
  • 这清楚地表明谷歌缺乏对 Python 的基本研究......
  • @MarkusUnterwaditzer 只需查看与该问题重复的问题列表的右侧。

标签: python


【解决方案1】:

在 Python 代码中,每个缩进级别必须对于缩进到至少该级别的每一行包含完全相同的空格和制表符序列。

实现这一点的最佳和最简单的方法是只为每个缩进级别使用空格,并且始终使用相同的数字。 The suggested number is four.

许多编辑器可以配置为用给定数量的空格替换制表符。

【讨论】:

    猜你喜欢
    • 2018-02-16
    • 1970-01-01
    • 2012-07-04
    • 2010-12-15
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    相关资源
    最近更新 更多