crsr.execute("SELECT * FROM tblmob")
res = crsr.fetchall()
for i in res:
nopol = i [2]
print(nopol)
and the ouput is row formating like this without the bullet
- B 9020 BCS
- B 9243 BQB
- B 9244 BQB
- B 9307 KXR
- B 9552 UXT
- B 9730 BCK
- B 9733 CXS
- B 9746 WRU
- B 9782 FXR
how can i get only one data from mylist i want get only B 9552 UXT please help me thanks
i have tried many time but is always fails
CodePudding user response:
I don't know how your res list look like, but if it is a simple list like this one:
res = ['B 9020 BCS', 'B 9243 BQB', 'B 9244 BQB', 'B 9307 KXR', 'B 9552 UXT', 'B 9730 BCK', 'B 9733 CXS' ,'B 9746 WRU', 'B 9782 FXR', 'B 9865 NCG']
you can get the single data by its index, like:
nopol = res[4]
this will return a string in index number 4 which is:
'B 9552 UXT'
please share what res look like.
CodePudding user response:
Add a conditional to your loop, so it only prints the desired element
for i in res:
if i == 'B 9552 UXT':
print(i)
Result:
'B 9552 UXT'