W
W
Worgen2018-09-26 03:53:43
Python
Worgen, 2018-09-26 03:53:43

How to return multiple variables?

Good afternoon, I would like to know if it is possible to return several values ​​to the vk.messages.send function? Those. so that the user ID is returned to the user, to the message Tekcn, to the attachment the photo ID, and if for example I need to return only the ID and the text of the message, then I could safely send and the function would look like vk.messages.send(user_id=user, message=text ).

def sendImage():
    number = random.randint(1, 99)
    number1 = random.randint(1,9)
    howMuch = vk.wall.get(domain='animart_pub', count=number)['items'][number-1]['attachments'][0]['photo']
    owner = howMuch['owner_id']
    id = howMuch['id']
    return 'photo{}_{}'.format(owner, id)

def readMessage(message):
    '''
    Проверяем на сходство сообщение
    '''
    if message=='Понедельник.Бот':
        return 'Пока не работает'
    elif message=='Вторник.Бот':
        return 'Пока не работает'
    elif message=='Среда.Бот':
        return 'Пока не работает'
    elif message=='Четверг.Бот':
        return 'Пока не работает'
    elif message=='Пятница.Бот':
        return 'Пока не работает'
    elif message=='Суббота.Бот':
        return 'Пока не работает'
    elif message=='Помощь.Бот':
        return 'Доступные следующие команды: \n' \
               'Понедельник.Бот \n' \
               'Вторник.Бот \n' \
               'Среда.Бот \n' \
               'Четверг.Бот \n' \
               'Пятница.Бот \n' \
               'Суббота.Бот \n' \
               'Аниме.Бот'
    elif message=='Аниме.Бот':
        sendImage()
    else:
        return 1

def userSend(user):
    '''
    Отправляем сообщение человеку
    '''
    if 'Аниме.Бот' == event.text:
        print("Сообщение для пользователя", user)
        vk.messages.send(user_id=user, message='Онимэ Брат', attachment=sendImage())
        time.sleep(4)
    elif 1 != readMessage(event.text):
        print("Сообщение для пользователя", user)
        vk.messages.send(user_id=user, message=readMessage(event.text), attachment=readMessage(event.text))
        time.sleep(4)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2018-09-26
@leahch

Can use dictionaries back and forth

def myfunc(a,b,c):
    return dict(a=a,b=b,c=c)
args = dict(a=1,b=2,c=3)
res = myfunc(**args)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question