S
S
swpavlov2020-02-03 17:00:21
Python
swpavlov, 2020-02-03 17:00:21

How to get the answer from one file to another file?

How to transfer the response about the performed operation from the db.py file to another filr.py?

def add_message(conn, user_id: int, name: str):
    c = conn.cursor()
    c.execute('SELECT * FROM user_message WHERE (user_id IS ? AND name IS ?)', (user_id, name))
    row = c.fetchone()
    if row is None:
        c.execute('INSERT INTO user_message (user_id, name) VALUES (?,?)', (user_id, name))
    conn.commit()


Here is where to get the answer, performed the operation (there is a user in the database) or not. Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2020-02-03
@swpavlov

in the filr.py file, do it at the beginning import dband then call add_message at the right place. and in the add_message method itself, at the end, write return rowfor example and already dance from what the function returns.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question