G
G
gadzhi152017-10-20 18:27:18
Python
gadzhi15, 2017-10-20 18:27:18

Extracting data from a database in Python. What is the best way to process it?

I am writing a bot for telegram. I use Python 3
There is a SQLlite base. Consists of 7 columns. id, name, ip
, port, login, password, telegram_id

c.execute("SELECT * FROM resto WHERE telegram_id LIKE ?", (key, )).fetchall()

Accordingly, if there is only one string, then a tuple is returned, and if there is already more than one (N), then a list of N elements is returned. For example:
<class 'list'>
[(1, 'Build', '192.168.1.1', '8080', 'admin', 'admin', '10'), 
(2, 'Build2', '192.168.1.2', '8080', 'admin', 'admin', '12')]

After that, I need to extract the data in order to make a GET request (pull out the ip, port and account information). With a tuple, everything is clear. If there are several rows returned, then the user is prompted to choose which account to choose (name field). But what about when there are several returned rows and they all go together as one array element? What would be the optimal solution? So far, two options come to mind: split into N list and then split elements by ' , '
What other options are there?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question