Create a PythonBox that outputs with Random after PEPPER Input

Overview

When you want to make a branch with Random in PythonBox

スクリーンショット 2015-06-26 18.35.37.png

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

    def onLoad(self):
        pass

    def onUnload(self):
        pass

    def onInput_onStart(self):
        import random
        num = random.randint(0, 1)
        if num == 0:
            self.onA()
        else:
            self.onB()

With this kind of implementation Tweak the code when you want to change the number of branches from two to three, Since you have to go from editing the box to increasing the output, Increase the output so that it will create a branch without permission.

Implementation

import numpy

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

    def onLoad(self):
        self.outputs = []
        for attr in dir(self):
            if callable(getattr(self, str(attr))) and "output" in str(attr):
                self.outputs.append(attr)

    def onUnload(self):
        self.outputs = []

    def onInput_onStart(self):
        r = numpy.random.randint(0, len(self.outputs))
        method = getattr(self, self.outputs[r])
        method()

Commentary

Entering a box from editing and increasing the output declares the box's methods. Use dir (self) to get the box properties during onLoad and Check if it can be executed with callable (whether it is a method), Append the method labeled output to self.outputs.

The method that appends to self.outputs is executed by onInput_onStart.

Recommended Posts

Create a PythonBox that outputs with Random after PEPPER Input
Create a chatbot that supports free input with Word2Vec
Create a PDF file with a random page size
Create a page that loads infinitely with python
Create a random number with an arbitrary probability density
Let's create a script that registers with Ideone.com in Python.
Create a life game that is manually updated with tkinter
Create a homepage with django
Create code that outputs "A and pretending B" in python
Create a heatmap with pyqtgraph
Tornado-Let's create a Web API that easily returns JSON with JSON
Create a web API that can deliver images with Django
Create a directory with python
[Golang] A program that determines the turn with random numbers
Create a program that can generate your favorite images with Selenium
[LINE Messaging API] Create a BOT that connects with someone with Python
Create a poster with matplotlib to visualize multiplication tables that remember multiplication
Create a compatibility judgment program with the random module of python.
A function that returns a random name
Create a virtual environment with Python!
Create a SlackBot service on Pepper
Create a 1MByte random number file
Create a poisson stepper with numpy.random
Create a random string in Python
Create a file uploader with Django
Create a BOT that can call images registered with Discord like pictograms
Create a web app that can be easily visualized with Plotly Dash
I made a plug-in "EZPrinter" that easily outputs map PDF with QGIS.
Create a Python function decorator with Class
[Python] A program that creates stairs with #
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a GUI app with Python's Tkinter
Create a large text file with shellscript
Create a star system with Blender 2.80 script
Create a virtual environment with Python_Mac version
Create a VM with a YAML file (KVM)
Create a simple web app with flask
Create a new dict that combines dicts
Create a word frequency counter with Python 3.4
[Python] Create a LineBot that runs regularly
Create a Connecting Nearest Neighbor with NetworkX
A typed world that begins with Python
Create a bot that boosts Twitter trends
Create a web service with Docker + Flask
Create a private repository with AWS CodeArtifact
Create a car meter with raspberry pi
Create a devilish picture with Blender scripts
Create a matrix with PythonGUI (text box)
Create a graph with borders removed with matplotlib
Create a bot with AWS Lambda that automatically starts / stops Instances with specific tags
A story that did not end with exit when turning while with pipe input
Create a UI that replaces VBA with PySimpleGUI (file dialog, list, log output)
A story that turned light blue in 4 months after starting AtCoder with python
[kotlin] Create an app that recognizes photos taken with a camera on android