this is a part of a code for picroft skill:

def handle_command_intent(self, message):
    if message.data["command"].upper() == "BLINK":

the "data" and "command" and "speak" didn't define in the code how does python found what data is? how about the other?

another problem that i have is in the code below:

class iterable(object):
    def __init__(self, values):
        self.values = values
        self.location = 0

my question is why haven't location be put in the def arguments like below?

def __init__(self, values, location)

and why a function like below should be define?

def __iter__(self):
    return self

The code that i ask about is in github.com/MycroftAI/picroft_example_skill_gpio/blob/master/….


The first line of code in your message is a function definition. The variable "message" is an argument, and so is defined by the function itself. The function must be called with an object with a "data" property. which will be accessed within the function as message.data.

The "self" variable, by convention, refers to a particular instance of a class.

The example is deeply into object oriented Python. I'd suggest working through a couple of simple function definitions so that you get comfortable with the idea of arguments, then try defining a simple class and creating two instances of it to learn a bit more about class and object. Then return to the example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.