skip to Main Content
    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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search