Answer the question
In order to leave comments, you need to log in
Problem with PYTHON strings?
I work with api.vk, the text from the last message is written to the variable, you need to get the balance:
Help, how to do this. It turns out that I need to get the numbers from the second line.
+code and exit
import vk
import time
import random
token = "" #Сюда вводим свой токен.
session = vk.Session(access_token = token)
api = vk.API(session, v = "5.95")
a=api.messages.getHistory(peer_id=-173401327, offset=0, count=1)
bal = a['items'][0]['text']
print(bal)
Answer the question
In order to leave comments, you need to log in
# Срезом определите ограничение числа
bal = int(a['items'][0]['text'].replace(',' '')[:7])
print(bal)
You can sequentially cut through split () with different conditions. Or use regexp.
s = """
Балансы:
Баланс $: 228,951
Баланс котяток: 0.67984234"""
import re
m = re.search(r"Баланс \$: (.+)", s)
if m:
print(m.group(1))
print(m.group(1).replace(',',''))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question