我的IndentationError看起来似乎无法解决. http://pastebin.com/AFdnYcRc.
#!/usr/bin/env python
import os
import glob
import shutil
import mutagen
from sys import exit
musicdir = raw_input("What directory are the music files located in? : ")
musfile = glob.glob(musicdir + '/' + "*.mp3")
musfile1 = glob.glob(musicdir + '/' + "*.flac")
musfile.extend(musfile1)
newmusicdir = raw_input("What directory should the music files be organized into? : ")
done = False
while not done:
for m in musfile:
if musfile:
try:
musta = mutagen.File(m, easy=True)
mar = str(musta['artist'][0])
mal = str(musta['album'][0]) …Run Code Online (Sandbox Code Playgroud) 嗨,我是python新手,我正在使用python工作NLP.我在写python中的if-else块时遇到错误.当我写作时,只有当时阻止它正常工作:
if xyzzy.endswith('l'):
print xyzzy
Run Code Online (Sandbox Code Playgroud)
进入冒号后,我按下回车键,它会自动将我带到正确的缩进处.
但是当我在print语句后按"Enter"键后尝试添加else块时,它正在考虑它只是IF块的声明,所以它给了我不正确的缩进,因为我想要阻止之后,而当我我试图写别阻止我的自我它给了我这个错误.
else:
^
Run Code Online (Sandbox Code Playgroud)
IndentationError: unexpected indent
那么在写完print语句后我该怎么办?输入显然不起作用,因为它正在向前移动光标,而当我使用空格来到正确的指针时它会给我一个错误.
我编写了以下程序,但不确定它有什么问题,它给出了:
File "Button_2.py", line 9
""" Initialise the Frame. """
^
IndentationError: expected an indented block
Run Code Online (Sandbox Code Playgroud)
这是我的代码的图像:

这里发生了什么?
我完全是一个绿色的手,我不知道我的代码有什么问题.我尝试多次调整它,但它没有工作,并expected an intended block在我运行代码时保持警报.
def abc(words_list):
number1 = 0
number2 = 0
for L in words_list:
if L[0] in 'aeiou':
number1 = number1 + 1
else:
number2 = number2 + 1
first_char = L[0]
for i in range(1,len[L]):
L[i-1] = L[i]
L[-1] = first_char
L = L + 'ay'
return(number1, number2)
Run Code Online (Sandbox Code Playgroud) 在顶部:
import pygame, sys
from pygame.sprite import Sprite
from pygame.locals import *
pygame.init()
Run Code Online (Sandbox Code Playgroud)
部分不工作:
class DetectionBox(Sprite):
def __init__(self):
Sprite.__init__(self)
self.img = pygame.Surface([SCREEN_WIDTH, SCREEN_HEIGHT/4], SRCALPHA, 32).convert_alpha()
self.pos = (0, SCREEN_HEIGHT - (SCREEN_HEIGHT/4)*3)
DETECT_BOX = DetectionBox()
Run Code Online (Sandbox Code Playgroud)
错误:NameError:未定义名称"self"
有人请解释为什么这不起作用,因为我不知道.它与其他所有类一起正常工作,所以它就是这个.
我是Django的新手,并在教程中尝试了这段代码.但是由于以下错误,我现在无法运行我的程序:
IndentationError at /
('unexpected indent', ('D:\\django_workspace\\django_bookmarks\\..\\django_bookmarks\\bookmarks\\views.py', 14, 4, ' return HttpResponse(output)\n'))
Request Method: GET
Request URL: http://localhost:8000/
Exception Type: IndentationError
Exception Value:
('unexpected indent', ('D:\\django_workspace\\django_bookmarks\\..\\django_bookmarks\\bookmarks\\views.py', 14, 4, ' return HttpResponse(output)\n'))
Exception Location: D:\django_workspace\django_bookmarks\..\django_bookmarks\urls.py in <module>, line 2
Python Executable: C:\Python26\python.exe
Python Version: 2.6.4
Python Path: ['D:\\django_workspace\\django_bookmarks', 'C:\\Python26', 'C:\\WINDOWS\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26\\lib\\site-packages']
Server time: Tue, 9 Mar 2010 19:18:32 +
Run Code Online (Sandbox Code Playgroud)
我的views.py文件代码是:
from django.http import HttpResponse, Http404
from django.contrib.auth.models import User
from django.template import Context
from django.template.loader import get_template …Run Code Online (Sandbox Code Playgroud) 在下面我得到错误
IndentationError: unindent does not match any outer indentation level (hisrel_split.py, line 25)
Run Code Online (Sandbox Code Playgroud)
哪elif条线.我检查了所有的缩进,甚至重新输入了大部分内容.要么我错过了一些明显的东西,要么有一些我不知道的微妙规则.有任何想法吗
from numpy import *
from pylab import *
import sys
ifp = open(sys.argv[1],"r").readlines()
data_1 = []
data_2 = []
data = []
last = int(ifp[-1].split()[0])
set_1 = range(int(round(last)/2))
set_2 = range(int(round(last)/2),(last+1))
for i in ifp:
d = i.split()
try:
data.append(eval(d[2]))
except:
continue
if eval(d[0]) in set_1 and eval(d[1]) in set_1:
try:
data_1.append(eval(d[2]))
except:
continue
elif eval(d[0]) in set_2 and eval(d[1]) in set_2:
print "yes"
Run Code Online (Sandbox Code Playgroud) 我试图在Python中的if语句中添加多个条件,如下所示:
if (h9 == h1 or h9 == h2 or h9 == h3 or h9 == h4 or h9 == h5 or h9 == h6 or h9 == h7 or h9 == h8) and (h10 == h1 or h10 == h2 or h10 == h3 or h10 == h4 or h10 == h5 or h10 == h6 or h10 == h7 or h10 == h8) :
do sth.
Run Code Online (Sandbox Code Playgroud)
基本上它是一个OR条件都h9和h10在同一时间.
但是,这不起作用,并给出如下错误:
IndentationError: unindent does not match any …
我刚开始学习python.在我第一次遇到python时,我遇到了问题.我正在学习定义一个函数.在一个简单的命令中,我得到一个预期的缩进块错误.请指教.我正在使用这种语法
>>>def hello():
...print "Hello"
Run Code Online (Sandbox Code Playgroud)
但是当我在"Hello"之后按下回车键时,我得到预期的缩进块错误实际上我必须将此函数定义如下
>>> def hello():
print "Hello"
print "Computers are Fun"
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的新手,这是我的前几行编码.
谢谢!
python ×9
indentation ×4
button ×1
class ×1
django-views ×1
if-statement ×1
pygame ×1
python-2.7 ×1
python-3.x ×1
self ×1