Python - 从文件中获取缩进错误
Python - Getting an Identation error out of the file
我正在尝试在 python 中编写一个小程序,没有什么复杂的,但是非常长。刚才,我修改了一个 'if' 语句的条件,然后通过 MacOS 终端 运行 它,因为它有一个 Python shell / IDLE(我没有知道它在英语里怎么叫)。
我的文档恰好有 456 行,我得到的 'IndentationError' 位于 'line 457',这是输出:
File "/Volumes/my usb key/MAIN_0.3.py", line 457
^
IndentationError: expected an indented block
我真的不知道该怎么办,因为我程序的最后几行都是注释。如果你想要一些代码,我会尽量简单地(用英语)为大家提供,但我想首先知道 运行 它在 'Terminal' 中是否有问题, 因为真的很奇怪。
编辑:这里是一些代码:
#coding= utf-8
#here I put a lot of variables(38), which are all 'int' or 'randint(x, y)'
#then I define some functions, which are all calculus
#here is the main loop :
while (a!=10) and (b > 10):
function_a(a)
c=0
while (c != 1) and (b > 0):
while b != 0:
print "\n"
d=randint(0,20)
if 0 <= d <= 3: #commentary explaining my program for my buddies at school
b=function_b(b, e, f, g, h, i, j, a, k, l)
if b <= 0: #commentary
m += n
p += a_b
if p > 1000: #commentary
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 3 < d <= 8: #commentary
b=function_b(b, e, f, g, q, r, s, a, k, t)
if b <= 0: #commentary
m += u
p += v
if p > 1000: #
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 8 < d <= 14: #commentary
b=function_b(b, e, f, g, w, x, y, a, z, k, a_a)
if b <= 0: #commentary
m += n
p += a_b
if p > 1000: #commentary
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 15 <= d <= 16:#commentary
a_c += 1
function_c()
if d == 17: #commentary
a_d += 1
function_d()
#boss commentary
if (d == 18) and (a_d == 0):
print " mkay"
time.sleep(2)
print " nope"
print " next door"
#commentary
if (d == 18) and (a_d >= 1):
print " arrived"
time.sleep(2)
print " wanna go ?"
print " yes - 1"
print " No - any other"
a_e=input(" ")
if a_e == 1:
#boss commentary
评论不是陈述,所以当你这样做时
if something:
# Comment
if
没有body。那是一个语法错误。如果你想要一个 do-nothing 占位符 body,那就是 pass
语句的目的。
if something:
# Comment
pass
我正在尝试在 python 中编写一个小程序,没有什么复杂的,但是非常长。刚才,我修改了一个 'if' 语句的条件,然后通过 MacOS 终端 运行 它,因为它有一个 Python shell / IDLE(我没有知道它在英语里怎么叫)。
我的文档恰好有 456 行,我得到的 'IndentationError' 位于 'line 457',这是输出:
File "/Volumes/my usb key/MAIN_0.3.py", line 457
^
IndentationError: expected an indented block
我真的不知道该怎么办,因为我程序的最后几行都是注释。如果你想要一些代码,我会尽量简单地(用英语)为大家提供,但我想首先知道 运行 它在 'Terminal' 中是否有问题, 因为真的很奇怪。
编辑:这里是一些代码:
#coding= utf-8
#here I put a lot of variables(38), which are all 'int' or 'randint(x, y)'
#then I define some functions, which are all calculus
#here is the main loop :
while (a!=10) and (b > 10):
function_a(a)
c=0
while (c != 1) and (b > 0):
while b != 0:
print "\n"
d=randint(0,20)
if 0 <= d <= 3: #commentary explaining my program for my buddies at school
b=function_b(b, e, f, g, h, i, j, a, k, l)
if b <= 0: #commentary
m += n
p += a_b
if p > 1000: #commentary
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 3 < d <= 8: #commentary
b=function_b(b, e, f, g, q, r, s, a, k, t)
if b <= 0: #commentary
m += u
p += v
if p > 1000: #
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 8 < d <= 14: #commentary
b=function_b(b, e, f, g, w, x, y, a, z, k, a_a)
if b <= 0: #commentary
m += n
p += a_b
if p > 1000: #commentary
p -= 1000
k += 1
print " BRAVO !"
print " now", k
time.sleep(1)
b += b_levelup
e += e_levelup
f += f_levelup
print " you won", b_levelup, "points"
time.sleep(1)
print " you won", e_levelup, "points"
time.sleep(1)
print " you won", f_levelup, "points"
time.sleep(1)
print "\n"*2
if 15 <= d <= 16:#commentary
a_c += 1
function_c()
if d == 17: #commentary
a_d += 1
function_d()
#boss commentary
if (d == 18) and (a_d == 0):
print " mkay"
time.sleep(2)
print " nope"
print " next door"
#commentary
if (d == 18) and (a_d >= 1):
print " arrived"
time.sleep(2)
print " wanna go ?"
print " yes - 1"
print " No - any other"
a_e=input(" ")
if a_e == 1:
#boss commentary
评论不是陈述,所以当你这样做时
if something:
# Comment
if
没有body。那是一个语法错误。如果你想要一个 do-nothing 占位符 body,那就是 pass
语句的目的。
if something:
# Comment
pass