python:作为函数参数的类实例

2024-09-25 00:31:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,我想使用类的实例作为函数的参数,如以下代码:

机器人

from Bot import Qhttp, Event
import func

bot = Qhttp()

@bot.on('message')
async def _Msg(event: Event):
    print(event.message)
    await func.dosomething(event)

bot.run(hots='0.0.0.0', port=23456)

func.py

async def dosomething(event):
    print(event.message)

Qhttp是一个基于Quart开发的对象,用于接收http post信息

message是事件对象中的字符串

async def _Msg(event: Event):中,字符串可以正常打印,但在async def dosomething(event):中,我无法获取字符串。它打印:

functools.partial(<bound method Qhttp.call_action of <Bot.Qhttp object at 0xMEMORYADDRESS>>, 'message')

如何访问async def dosomething(event):中的message字符串


Tags: 对象字符串importeventmessageasyncdefbot