T
T
Tim2452020-11-28 21:50:58
Python
Tim245, 2020-11-28 21:50:58

Why is my mas_user_id variable not updated?

I want a number to be added to the sql table and immediately displayed, but when it is added, the mas_user_id variable is
not updated, although I call another python file where it should be updated here are the codes

from user_id_id import peremenna_user_id, mas_user_id
    if message.text == 'Перейти в корзину!':
        user_id = message.from_user.id
        peremenna_user_id = peremenna_user_id + '\n'
        peremenna_user_id = peremenna_user_id + str(user_id)

        conn = sqlite3.connect("telebot00.db")  # или :memory: чтобы сохранить в RAM эти все 6 строчек тупо записывают в бд афйди на них можно вообще внимание не обращать всё отлично работает 
        cursor = conn.cursor()
        cursor.execute(f"""INSERT INTO users_id (user_id) VALUES(?)""",
                       (user_id,))
        conn.commit()
        conn.close()
        call(["python", "user_id_id.py"]) это вызов файла какрз таки который обновляет эту переменную mas_user_id

        print(mas_user_id) тут я хочу просто вывести но эта переменная не обновляеться


the second CODE that is called by the call(["python", "user_id_id.py"]) method I will immediately say the file is called checked)
but the variable is not updated, I don’t understand why :(
import sqlite3
peremenna_user_id = ''
mas_user_id = []
con = sqlite3.connect("telebot00.db")
cur = con.cursor()

result = cur.execute("""SELECT * FROM users_id""").fetchall()
# Вывод результатов на экр
for user_id in result:
    mas_user_id.append(str(user_id[1]))
    peremenna_user_id = peremenna_user_id + str(user_id[1])
    peremenna_user_id = peremenna_user_id + '\n'
print(mas_user_id,' 123')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-11-28
@Tim245

You imported it once - it was initialized once. Everything is correct. If you really need to do this, then wrap your loop from user_id_id into a function, return mas_user_id in this function, and execute this function in the main file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question