if len(trashed_files) == 0 :
print "No files trashed from current dir ('%s')" % os.path.realpath(os.curdir)
else :
index=raw_input("What file to restore [0..%d]: " % (len(trashed_files)-1))
if index == "*" :
for tfile in trashed_files :
try:
tfile.restore()
except IOError, e:
import sys
print >> sys.stderr, str(e)
sys.exit(1)
elif index == "" :
print "Exiting"
else :
index = int(index)
try:
trashed_files[index].restore()
except IOError, e:
import sys
print >> sys.stderr, str(e)
sys.exit(1)
Run Code Online (Sandbox Code Playgroud)
我正进入(状态:
elif index == "" :
^
IndentationError: expected …Run Code Online (Sandbox Code Playgroud) 我有一个Python脚本:
if True:
if False:
print('foo')
print('bar')
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行我的脚本时,Python提出了一个IndentationError:
File "script.py", line 4
print('bar')
^
IndentationError: unindent does not match any outer indentation level
Run Code Online (Sandbox Code Playgroud)
我一直在玩我的程序,我还能够产生其他三个错误:
IndentationError: unexpected indentIndentationError: expected an indented blockTabError: inconsistent use of tabs and spaces in indentation这些错误意味着什么?我究竟做错了什么?我该如何修复我的代码?
我只是无法弄清楚这有什么问题......
#!/usr/bin/env python
#
# Bugs.py
#
from __future__ import division
# No Module!
if __name__ != '__main__':
print "Bugs.py is not meant to be a module"
exit()
# App
import pygame, sys, random, math
pygame.init()
# Configuration Vars
conf = {
"start_energy": 50,
"food_energy": 25,
"mate_minenergy": 50,
"mate_useenergy": 35,
"lifespan": 300000
}
class Bugs:
def __init__(self):
self.list = []
self.timers= {}
# Names / colors for sexes
self.sex = ["Male", "Female"]
self.color = ["#CBCB25", "#A52A2A"]
# Bug info tracking …Run Code Online (Sandbox Code Playgroud) 我是初学者python,
我有这个错误:
Error :
def on_data(self,data):
^
IdentationError : unindent does not match any outer indentation level
Run Code Online (Sandbox Code Playgroud)
我用notepad++in 编码windows 8.1.我不明白为什么我有这个错误,我已经注意到标签和空间.
我想在self.file中保存数据
这是我的代码:
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
from tweepy import Stream
import tweepy
import time
class StdOutListener(StreamListener):
def __init__(self,file):
self.file = file
def on_data(self, data):
print data
self.file.write(data)
return True
def on_error(self, status):
print status
def main() :
file = open('work.txt','w')
listn = StdOutListener(file)
consumer_key=""
consumer_secret=""
access_token=""
access_token_secret=""
auth = tweepy.OAuthHandler(consumer_key, …Run Code Online (Sandbox Code Playgroud) 运行这段代码时:
#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
Run Code Online (Sandbox Code Playgroud)
我收到了错误
文件"tweetpicture.py",第17行
Run Code Online (Sandbox Code Playgroud)os.system("fswebcam -r 960x720 -d /dev/video0 " + timestamp + ".jpg") ^ IndentationError:unindent与任何外部缩进级别都不匹配
这可能意味着什么?我已经四处搜索,人们已经说过有标签和空格的混合,但我完全不理解这一点,因为我还是Python的新手,这是我的前几行编码.
谢谢!