Z
Z
zxqb2020-04-08 20:31:53
Python
zxqb, 2020-04-08 20:31:53

How to implement the output of data from the database based on the number of data?

The user creates a request to the database. Upon request, an array with the number of lists from one to infinity can come out. Depending on the number of lists, you need to correctly display information to the user.


Example:
data = cursor.fetchall()
#data - accordingly, the resulting array, for example - [(1, 2, 3), (1, 2, 3), (1, 2, 3), (1, 2, 3 )...]
With the help of len(data) I'll get the number of lists in the array
And then I still can't figure out what to do.. The answer should be in the message, two lines each. The number of messages should depend on the number of lines.
#sms - message
sms = data[0] #if one line
sms = data[0], data[1] #if two
If more than two, then only 0-1 should be taken from the data array, then 2 or 2-3 lines etc
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xDimus, 2020-04-08
@xDimus

something like this, only the check needs to be added

for i in range(0, len(data), 2): print(data[i], data[i+1])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question