I have a script to send a query to MySQL and write result into the file. The issue I have is the text output looks like this:
(u'DB11A-DBD27', u'DB11A-DBD28')(u'DB62A-DBD1', u'DB62A-DBD2')(u'DB62A-DBD11', u'DB62A-DBD12')...
And I would like it to look like this:
DB11A-DBD27
DB11A-DBD28
DB62A-DBD1
DB62A-DBD2
DB62A-DBD11
DB62A-DBD12
...
Here is the code:
cnx = connectDB.cnx
query = "SELECT DB-P1,DB-P2 FROM distribution"
cur = cnx.cursor()
sql = cur.execute(query)
results = cur.fetchall()
f = open('Master.txt', 'w')
for row in results:
row = str(row)
print "".join(row )
f.write(row)
f.close()
I tried strip()
but kept getting type errors. Does anyone know how I can convert these tuples to list of string with each item in a new line as shown above?