0
def makeModels():
    make = "Acura"
    models = []
    for model in (cursor.execute('select model from Car where make like ' + "'{}'".format(make))):
        models.append(str(model))

I get in Return:

('CL', )
('EL', ) 
('ILX', )
('Integra', )
('MDX', )
('NSX', )
('RDX', )
('RL', )
('RLX', )
('RSX', )
('TL', )
('TLX', )
('TSX', )
('ZDX', )

Now This is going into a ComboBox and I I cant have it look like this. I have Class With the same info So my main question is how can I change the format.. What i understand is when you pull something from SQL its and object.

4
  • Can you specify the output format? Commented Jul 15, 2021 at 13:55
  • 1) Do not pass parameters in this way, use bind variables instead. 2) cursor.fetchmany() returns list of tuples, so just transform it to list of strings Commented Jul 15, 2021 at 14:54
  • Does this answer your question? How to get first element in a list of tuples? Commented Jul 15, 2021 at 14:55
  • @astentx could you explain to me or send me a link on how to use fetchmany? Commented Jul 15, 2021 at 17:06

2 Answers 2

1

just by changing

models.append(str(model)) --> models.append(model[0])

Sign up to request clarification or add additional context in comments.

3 Comments

this worked, why does it work if you could explain
I am glad it worked. The query return a collection of tuple. Each tuple contains one element at offset 0. I hope it is clear now.
Feel free to accept the answer if it works for you.
1

Try this:

def makeModels():
    make = "Acura"
    query = 'select model from Car where make like {}'.format(make))
    cursor.execute(query)

    models = [list(i)[0] for i in cursor.fetchall()]

2 Comments

could you explain how I would use this to get a specific query?
I edited my answer according to your query hope this works for you. @balderman already explained how the query return and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.