Answer the question
In order to leave comments, you need to log in
How to pass variable from python vk_api function?
Hello, there is a condition under which the bot asks the user for a list of products, and after that it goes into a function that takes a given value and translates them into an array, everything worked, but then I realized that the function that I run starts to work forever, and also in the future I will have to get data from the variable in which this list is written, I could not organize it, and also in the future I will have to use the value of the variable with the products in other functions, how to pass this value and do what I have in mind? The code is below :
Ps-I know that the code is bad enough, because I started to shamanize it and went into a complete dead end and threw off the version of the code in which I came to a dead end
#Добавление списка продуктов в массив
def parser(self):
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.obj.text != '':
if event.from_user :
a = event.obj.text.split(',')
print(a)
vk.messages.send(
user_id=event.obj.from_id,
random_id=get_random_id(),
message="Продукты добавлены в ваш портфель",
keyboard=keyboard.get_keyboard())
def port(self,a):
if parser.a !="":
vk.messages.send(
user_id=event.obj.from_id,
random_id=get_random_id(),
message="Твой портфель состоит из продуктов: \n")
for i in range(a):
vk.messages.send(
user_id=event.obj.from_id,
random_id=get_random_id(),
message=a[i]+"\n")
else:
vk.messages.send(
user_id=event.obj.from_id,
random_id=get_random_id(),
message="Ваш портфель пуст, добавьте в него продукты:)",
keyboard=keyboard.get_keyboard())
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.obj.text != '':
if event.from_user :
elif event.obj.text == 'Добавить продукты':
vk.messages.send(
user_id=event.obj.from_id,
random_id=get_random_id(),
message="Введите названия ваших продуктов через запятую.")
parser()
#---------------------------------------------------------------------------------------------
elif event.obj.text == 'Мой портфель':
vk.messages.send(
user_id=event.obj.from_id,
random_id=get_random_id(),
message=port(parser),
keyboard=keyboard.get_keyboard())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question