2013-09-01 56 views
2

當運行這段代碼:PYTHON錯誤:IndentationError:取消縮進不匹配任何外部縮進級別

#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 

我得到的錯誤

File "tweetpicture.py", line 17

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

unindent does not match any outer indentation level

什麼能這可能意味着什麼?我已經搜索過,人們都說有多種選項卡和空格,但是我完全不理解這一點,因爲我對Python還很陌生,這是我編寫的第幾行代碼。

謝謝!

+9

只用空格鍵重新調整代碼,看看會發生什麼。 –

+4

這個問題爲什麼downvoted?這是清楚的,並顯示研究工作。 –

+0

它清楚地顯示了缺乏關於Python的基本谷歌研究... – BartoszKP

回答

6

在Python代碼中,每個級別的縮進必須包含的每個縮進到至少該級別的行的空格和製表符的序列完全相同。

實現此目的的最佳和最簡單的方法是對每個縮進級別只使用空格,始終使用相同的數字。 The suggested number is four

許多編輯器可以配置爲用指定數量的空格替換製表符。

相關問題