Answer the question
In order to leave comments, you need to log in
Why does it lose self when importing a class in python?
I create a class, in the function.py file
class fnc():
def send_msg(self, message = None,attachment = None,**args):
vk.messages.send(
peer_id = peer_id,
random_id = get_random_id(),
disable_mentions = 1,
message = message,
attachment = attachment, **args)
import vk_api
import requests
from vk_api.bot_longpoll import VkBotLongPoll
from vk_api.bot_longpoll import VkBotEventType
from vk_api.utils import get_random_id
from function import fnc
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
user_stat_id = event.obj['message']['from_id']
vk_message = event.obj['message']
peer_id = vk_message['peer_id']
text = vk_message['text']
if text.lower() == '1':
fnc.send_msg(message="text")
Answer the question
In order to leave comments, you need to log in
You need to instantiate the class.
fnc = fnc()
And in general it would be better
class Fnc:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question