我的覆盆子pi python代码包含。
try:
while True:
blockHits = mc.events.pollBlockHits()
if blockHits:
for blockHit in blockHits
每当我启动代码时,它都会显示无效语法并突出显示if。 顺便说一句,这是为了我的世界。
答案 0 :(得分:2)
您未能向我们显示属于您的try
statement的except
或finally
块,但if
声明仍必须属于try
套房。但是,它没有缩进到足以成为try
套件的一部分。
将if
语句缩进到try:
块中,或将其放在finally:
或except:
套件之后。如果您没有,则需要添加一个,如果没有,则无法使用try:
。
您似乎试图在this post中输入代码;您会注意到if
位于while
循环内:
try:
while True:
#Get the block hit events
blockHits = mc.events.pollBlockHits()
# if a block has been hit
if blockHits:
# for each block that has been hit
for blockHit in blockHits:
#Create and run the exploding block class in its own thread
# pass the position of the block, fuse time in seconds and blast radius
# threads are used so multiple exploding blocks can be created
explodingBlock = ExplodingBlock(blockHit.pos, 3, 3)
explodingBlock.daemon
explodingBlock.start()
time.sleep(0.1)
except KeyboardInterrupt:
print("stopped")
缩进在Python中非常重要;它的作用是将语句分组到属于一起的块(套件)中,并且您的尝试打破了对try
套件应该如何结束的期望。