简体   繁体   English

期望缩进的块python choregraphe

[英]expected an indented block python choregraphe

Hi I am new in Python and this is an error that many people have but I could'nt be helped by any other thread. 嗨,我是Python新手,这是很多人都犯的错误,但是其他任何线程都无法帮助我。 The code is straight from this tutorial . 该代码直接来自于本教程 And it posts:[ERROR] behavior.box :FMBox::createPythonModule:0 _Behavior__lastUploadedChoregrapheBehaviorbehavior_1291762048__root__headnod_1: User class evaluation failed with the error: ('expected an indented block', ('', 19, 11, 'motionProxy.angleInterpolation(names,[0.0,1.0],times,True)\\n')) 并发布:[ERROR] behavior.box:FMBox :: createPythonModule:0 _Behavior__lastUploadedChoregrapheBehaviorbehavior_1291762048__root__headnod_1:用户类评估失败,并显示以下错误:('expected indented block',(('',19,11,'motionProxy.angleInterpolation(names, [0.0,1.0],times,True)\\ n'))

Thank you in advance 先感谢您

class MyClass(GeneratedClass):
def __init__(self):
    GeneratedClass.__init__(self)

def onLoad(self):
    #put initialization code here
    pass

def onUnload(self):
    pass

def onInput_onStart(self):
    motionProxy=ALProxy("ALMotion")
    names = ['HeadYaw','HeadPitch']
times = [[0.5],[0.5]]
motionProxy.angleInterpolation(names,[0.0,0.0],times,True)

for i in range(3):
motionProxy.angleInterpolation(names,[0.0,1.0],times,True)
motionProxy.angleInterpolation(names,[0.0,-1.0],times,True)

motionProxy.angleInterpolation(names,[0.0,0.0],times,True)

self.onStopped()

def onInput_onStop(self):
    self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
    self.onStopped() #activate the output of the box

Error says that your code is incorrectly indented. 错误表示您的代码缩进不正确。 For python you need to indent each block of code, like class body, for loop body, etc: 对于Python需要缩进的每个代码块,像class的身体, for循环体,等等:

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        #put initialization code here
        pass

    def onUnload(self):
        pass

    def onInput_onStart(self):
        motionProxy=ALProxy("ALMotion")
        names = ['HeadYaw','HeadPitch']

        times = [[0.5],[0.5]]
        motionProxy.angleInterpolation(names,[0.0,0.0],times,True)

        for i in range(3):
            motionProxy.angleInterpolation(names,[0.0,1.0],times,True)
            motionProxy.angleInterpolation(names,[0.0,-1.0],times,True)

        motionProxy.angleInterpolation(names,[0.0,0.0],times,True)

        self.onStopped()

    def onInput_onStop(self):
        self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
        self.onStopped() #activate the output of the box

Check this chapter from Dive Into Python - Indenting Code . 查阅《深入Python 缩进代码》中的这一章。 Also just a note that code above is not complete, it is a part of something bigger, so you anyway can't just use this code alone to do something. 还需要注意的是,上面的代码并不完整,它是更大代码的一部分,因此无论如何您都不能仅使用此代码来做某事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM