I am using pyhton 2.7 to compare datasets. I call a select
statement to pull from the two tables. str(row[4])
is always blank. I need to always write a "T" into that column.
Is there a way to write into str(row[4])
during the g.write
statement I use in the below code?
This is part of my code:
## This is used to connect to our database and run the sql statement.
def RunSQLStatement(sql):
conn = psycopg2.connect(Connect2DB())
cursor = conn.cursor()
cursor.execute(sql)
alias_data = cursor.fetchall()
cursor.close()
conn.close()
return alias_data
def selectFoisp():
with open(outTemp_file, 'w') as g:
strGetDiffer = """SELECT c.foi_id, c.title, c.feat_type, c.feat_subtype, c.upd_type, p.foi_id, p.title
FROM foisp c, foisp_prior p
WHERE (c.foi_id = p.foi_id)
AND (c.title <> p.title)"""
extract_rows = RunSQLStatement(strGetDiffer)
for row in extract_rows:
g.write(str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + ',' + str(row[3]) + ',' + str(row[4]) + ',' + str(row[5]) + ',' + str(row[6]) + '\n')