Skip to content

Commit 25e5b3a

Browse files
committed
basic sql2csv
1 parent 0523b16 commit 25e5b3a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

24_sql2csv.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
import csv
3+
import sqlite3
4+
5+
if len(sys.argv) < 3:
6+
print "Use: {0} DATABASE_NAME TABLE_NAME".format(sys.argv[0])
7+
exit()
8+
9+
conn = sqlite3.connect(sys.argv[1])
10+
cur = conn.cursor()
11+
data = cur.execute("SELECT * FROM {0}".format(sys.argv[2]))
12+
13+
with open('output.csv', 'wb') as f:
14+
writer = csv.writer(f)
15+
writer.writerows(data)
16+
17+
conn.close()

readme.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
1. **20_restore_file_from_git.py**: Restore file from Git History
2323
1. **21_twitter_bot.py**: Twitter Bot
2424
1. **22_git_tag.py**: Create Git Tag based on a commit
25-
1. **23_flask_session_test.py**: Just a simple app to see if the sessions are working.
25+
1. **23_flask_session_test.py**: Just a simple app to see if the sessions are working
26+
1. **24_sql2csv.py**: SQL to CSV.

0 commit comments

Comments
 (0)