Facing error trying to pull out data from column - Mailing list psycopg

From Shaan Repswal
Subject Facing error trying to pull out data from column
Date
Msg-id CALa+hEQRybA8C7H7ZSZg4z83UGYR0AG83RNcwkSzCdoMSMMKLw@mail.gmail.com
Whole thread Raw
Responses Re: Facing error trying to pull out data from column  (Adrian Klaver <adrian.klaver@aklaver.com>)
List psycopg
So here is my double loop:-

for col in colnames[3:]:
    for name in names:
        query = "select format('SELECT %I FROM inventory WHERE name = {}, '{}')".format(name, col)
        cur.execute(query)      #This is line 18
        query_str = cur.fetchone()[0]
        cur.execute(query_str)
        print(cur.fetchone())

And this is the error it is giving me:-

Traceback (most recent call last):
  File "C:\Python34\psycopg2\printing colnames.py", line 18, in <module>
    cur.execute(query)
psycopg2.ProgrammingError: syntax error at or near "25"
LINE 1: ...ventory WHERE name = Polyester Direct High Gloss, '25 LTRS')

Help me out folks.

My table columns are like this :-
name code type '25 LTRS' '12 LTRS' '26.2 LTRS' '500 ML'.... and so on...

And I want to print and cycle through all of the LTRS/ML (quantity columns) for every product name that I have. How do I go about that?

What am I doing wrong here?

psycopg by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Re: Pass parameters to cursor.execute('Listen ')?
Next
From: Adrian Klaver
Date:
Subject: Re: Facing error trying to pull out data from column