print function in python3.1
Anjanesh Lekshminarayanan
mail at anjanesh.net
Mon Nov 23 10:55:54 EST 2009
> Maybe it would help if you explained what you are actually trying to
> accomplish.
import csv
f = csv.reader(open('data.txt'), delimiter='\t') # 2GB text file
sql = "INSERT INTO `data` VALUES (NULL,%s,%s,%s,%s,%s);"
for row in f:
print (sql, (row[0],row[1],row[2],row[3],row[4]))
$ python3 parse.py3 > data.sql
But because of print() being a function in Py3,
print (sql, (row[0],row[1],row[2],row[3],row[4]))
prints
INSERT INTO `data` VALUES (NULL, '%s', '%s', '%s', '%s', '%s');
('142', 'abcde', '2006-03-01 05:17:14', '', '')
instead of
INSERT INTO `data` VALUES (NULL, '142', 'abcde', '2006-03-01 05:17:14', '', '');
Anjanesh
More information about the Python-list
mailing list