Understand Python for Pepper development. -Python box self-made function-

Preface

Knowledge of Python is essential for developing Pepper and NAO. Therefore, I will continue to aim to be able to create and use Python boxes, especially functions. Also, I haven't met many people who handle Choreographe who originally used python, so I would like to write an explanation so that even such people can improve the python box.

Development environment

Model name: MacBook Pro OS : Yosemite 10.10.3 Processor name: Intel Core i5 2.6 GHz Memory: 16 GB Graphics: Intel Iris 1536MB Choreographe : 2.3.1

python2.7

Main subject

Let's go to the main subject quickly.

Premise

Basically, the project is:

スクリーンショット 2015-07-17 16.37.53.png

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

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

    def onUnload(self):
        #put clean-up code here
        pass

    def onInput_onStart(self):
        #I need output, so self.onStopped()Enable
        self.onStopped() #activate the output of the box
        #pass #Comment out because it is not necessary

    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

I will start playing with it from here.

function

Argumentless function creation

First, let's create a simple function.

def testFunc(self):
	pass

I think it's okay to feel like this.

def testFunc(self):

This is what I call an argumentless function. Be sure to write the self variable because it is a variable that is passed to any function.

pass

This shows an empty function.

Function call with no arguments

def onInput_onStart(self):
	self.testFunc() #In this way, you can specify the method of your class as ◯◯.
	self.onStopped() #activate the output of the box

Function creation with arguments

First, let's create a simple function.

def testFunc2(self,a,b):
	c=a*b
	self.logger.info(c)

I think it's okay to feel like this.

def testFunc(self):

This is what I call an argumentless function. Be sure to write the self variable because it is a variable that is passed to any function.

Function call with arguments

def onInput_onStart(self):
	self.testFunc2(10,20) #In this way, you can specify the method of your class as ◯◯.
	self.onStopped() #activate the output of the box

Output result

200

Impressions

For the time being, it will end around here.

Recommended Posts

Understand Python for Pepper development. -Python box self-made function-
Understand Python for Pepper development. -Introduction to Python Box-
Python #function 2 for super beginners
[For organizing] Python development environment
Make a Tweet box for Pepper
Python development environment options for May 2020
Emacs settings for Python development environment
Python #len function for super beginners
Python development environment for macOS using venv 2016
python function ①
[Python] function
6 Python libraries for faster development and debugging
Building a Python development environment for AI development
python function ②
Python Box Concept (Pepper Tech Fes Tech Session)
[Python] I tried substituting the function name for the function name
Note for formatting numbers with python format function
Pepper (first edition for general sale) development started
2016-10-30 else for Python3> for:
python [for myself]
python enumerate function
[Python] Generator function
Python> function> Inner function
Python function decorator
Directory structure for test-driven development using pytest in python
Explore Alibaba Cloud Function Compute for DevOps using Python 3.0
Today's python error: invalid keyword argument for this function
Electron is the best solution for Python multi-platform development
[Python for Hikari-] Chapter 06-01 Functions (Intrinsic Functions and Function Definitions)
Personal best practices for VS Code-fronted Python development environments
AWS SDK for Python (Boto3) development in Visual Studio 2017
python memo (for myself): About the development environment virtualenv