Q:

converting columns to postgresql database

suppose I have a list of columns in python of equal lengths (in the example below, each column has 4 elements, but in my actual work each column has around 500+ elements):
col0 = [1, 12, 23, 41]   # also used as a primary key
col1 = ['asdas','asd', '1323', 'adge']
col2 = [true, false, true, true]
col4 = [312.12, 423.1, 243.56, 634.5]

and I have a postgresql table already defined, with columns: Col0 (integer, also primary key), Col1 (character varying), Col2 (boolean), Col3 (numeric)
I wrote the following code to connect to the postgresql database (which seemed to have worked fine):
import psycopg2
...
conn = psycopg2.connect("dbname='mydb' user='myuser' host='localhost' password = 'mypwd')
cur = conn.cursor()

Now suppose I want to push the columns to postgresql table myt where I want the rows to populated as :
 Col1  Col2     Col3   Col4
 1     'asdas'  true   312.12
 12    'asd'    false  423.1
 ...

I saw examples on SO such as this one where the example is for reading from a csv file:
for row in reader:
    cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (variable1, variable2))

(a) Can I adopt something similar for my case? Would this work:
for i in range(0, len(col0)):
    cur.execute("INSERT INTO myt (Col1, Col2, Col3, Col4) VALUES (%??, %s, %??, %f)", (col0[i], col1[i], col2[i], col3[i]))

(b) If yes, what is the type specifier for python integer, boolean, float types , when the corresponding postgresql types are integer, boolean and numeric?
(c) Also, what if I have 40 tables, instead of 4 tables. Do I have to write a long line like this:
   "INSERT INTO myt (Col1, Col2, ..., Col40) VALUES (%d, %s, ..., %f)", (col0[i], ...))

A:

a,b:
yes, that will work, psycopg2 uses %s to represent all types, that's just the way it works.(so don't use %?? etc...)
c:
"insert into {t} ({c}) values ({v})".format(
   t=tablename,
   c=','.join(columns_list),
   v=','.join(['%'] * len(columns_list))

gets you closer to a universal insert expression, but you still need to loop...

