[Tutor] CSV file processing...

Spencer Parker inthefridge at gmail.com
Fri Mar 21 20:44:32 CET 2008


That loop was some weird indentation that was caused when I pasted it...it
wasn't suppose to be indented like that...

On Fri, Mar 21, 2008 at 1:42 PM, Spencer Parker <inthefridge at gmail.com>
wrote:

> This is all that I get when I run it...
>
> Traceback (most recent call last):
>   File "./loadcsv.py", line 23, in ?
>     co.execute("""
>   File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 148,
> in execute
>     query = query % db.literal(args)
> TypeError: not all arguments converted during string formatting
>
>
>
> On Fri, Mar 21, 2008 at 1:34 PM, Kent Johnson <kent37 at tds.net> wrote:
>
> > Spencer Parker wrote:
> > > I posted it in a previous message on the list...but here it is...
> >
> > Looks new to me...
> > >
> > > #!/usr/bin/python
> > >
> > > import MySQLdb
> > > import csv
> > > import sys
> > >
> > > try:
> > >     db = MySQLdb.connect (host = "localhost",user = "root",passwd =
> > > "Ch33s3Monk3y",db = "xenstats")
> > > except MySQLdb.Error, e:
> > >     print "Error %d: %s" % (e.args[0], e.args[1])
> > >     sys.exit (1)
> > >
> > > try:
> > >     co = db.cursor()
> > >     csv_data = csv.reader(file('output.txt','r'))
> > >     headers = csv_data.next()
> > >     row = csv_data.next()
> > >     prefix = row[:20]
> > >     for i in range(20, len(row), 7):
> > >         next = prefix + row[i:i+7]
> > >
> > >         for row in csv_data: print next
> >
> > Why do you have this loop? You only want to process one row, right?
> >
> > >         co.execute("""
> > >             INSERT INTO stats VALUES
> > >
> > (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);
> > >         """,row)
> >
> > Should be next - the processed data - not row - the raw data.
> >
> > You still didn't show the actual error message. After the traceback
> > there should be an error.
> >
> > Kent
> >
>
>
>
> --
> Spencer Parker
> _______________________________________________________
>
> "if you can't go to heaven, may you at least die in Ireland."
>
> _______________________________________________________
>



-- 
Spencer Parker
_______________________________________________________

"if you can't go to heaven, may you at least die in Ireland."

_______________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080321/1b090191/attachment.htm 


More information about the Tutor mailing list