Skip to navigation
Export mysql output to csv and compress it in python
07.12.13
c = self.db.cursor() c.execute("SELECT * FROM Mytable") rows = c.fetchall() rows = '\n'.join('\t'.join('%s' % field for field in row) for row in rows) f= open(mytable.csv', 'w') f.write(rows) f.close() f_in = open(mytable.csv', 'rb') f_out = gzip.open(mytable.csv.gz', 'wb') f_out.writelines(f_in) f_out.close()
Reply
Anonymous
Information Epoch 1732508699
ACID (Atomicity, Consistency, Isolation, and Durability)
Home
Notebook
Contact us