コード例 #1
0
    def test_import():
        def some_function():
            return "hello, polyglot world!"
        polyglot.export_value(some_function)
        imported_fun0 = polyglot.import_value("some_function")
        assert imported_fun0 is some_function
        assert imported_fun0() == "hello, polyglot world!"

        polyglot.export_value("same_function", some_function)
        imported_fun1 = polyglot.import_value("same_function")
        assert imported_fun1 is some_function
        assert imported_fun1() == "hello, polyglot world!"
コード例 #2
0
                    return f"No gif found for {args}"
            elif command == "=":
                return f"You sent a command with arguments: {args}"
            elif command == "help":
                return """
                /img TERM
                /= CODE
                """
            elif command == "plot":
                return r_plot(args)
            else:
                return f"[{sender}] Unknown command /{command}"
        except:
            error = io.StringIO()
            traceback.print_exc(file=error)
            return error.getvalue()
    return f"[{sender}] {msg}"


def validate(sender, senderTopic, message, receiver, receiverTopic):
    print(f"Called from python with {sender=}, {receiver=}, {message=}")
    return senderTopic == receiverTopic


class ChatMessageHandler:
    isValid = staticmethod(validate)
    createMessage = staticmethod(transform_message)


export_value("ChatMessageHandler", ChatMessageHandler)
コード例 #3
0
import site
import numpy as np
import polyglot as poly


def heartAnalysis():
    heartData = np.genfromtxt('heart.csv', delimiter=',')
    peopleWhoHasChestPainTypeTwo = np.where((heartData[:, 2] > 1)
                                            & (heartData[:, 2] < 3)
                                            & ((heartData[:, 0]) > 60))
    dataOfPeopleWith3ChestPain = heartData[np.where(heartData[:, 2] > 2)]
    averageAgeofPeopleWith3ChestPain = np.average(
        dataOfPeopleWith3ChestPain[:, 0])
    print(averageAgeofPeopleWith3ChestPain)
    # Average age of people who are getting level 3 and greater chest pain
    return str(averageAgeofPeopleWith3ChestPain)


poly.export_value("heartAnalysis", heartAnalysis)

heartAnalysis()