0

I am trying to convert my sql query output into a list to look a certain way.

Here is my code:

def get_sf_metadata():

    import sqlite3
    #Tables I want to be dynamically created
    table_names=['AcceptedEventRelation','Asset', 'Book']

    #SQLIte Connection
    conn = sqlite3.connect('aaa_test.db')
    c = conn.cursor()

    #select the metadata table records
    c.execute("select  name, type from sf_field_metadata1  limit 10 ")
    print(list(c))


get_sf_metadata()

Here is my output:

[('Id', 'id'), ('RelationId', 'reference'), ('EventId', 'reference')]

Is there any way to make the output looks like this:

[Id id, RelationId reference, EventId  reference]

1 Answer 1

1

You can try

print(["{} {}".format(i[0], i[1]) for i in list(c)])

That will print you

['Id id', 'RelationId reference', 'EventId reference']
Sign up to request clarification or add additional context in comments.

Comments

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.