简体   繁体   中英

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. 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'))

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:

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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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