[Tutor] CSV file processing...

Spencer Parker inthefridge at gmail.com
Fri Mar 21 18:47:09 CET 2008


So if my long row is row two...how do I tell it to use row 2?

On Thu, Mar 20, 2008 at 5:42 PM, Kent Johnson <kent37 at tds.net> wrote:

> Spencer Parker wrote:
> > I am trying to read a CSV file and the get that information into a MySQL
> > database.  I am able to do this, but I have a small problem.  I have a
> > piece of software that runs and each iteration is one like.  It only
> > runs once right now; there is only one line + the headers.  I use the
> > csv module to kill the headers and import the one line.  The problem
> > is...I need to have it split the csv file at some point. I need to first
> > 20 items taken off and then have the next 7 + the first 20 imported into
> > the database...then have it do this for the next 7 + the first 20...so
> > on and so forth until hits the end of the line.
>
> I'm not sure I understand. It sounds like you have a very long line of
> data from the csv file and you want to split it into groups of 7, after
> taking the first 20 items. If that is correct, something like this might
> work:
>
> row = ... # your long row
> prefix = row[:20] # the twenty items that repeat
> for i in range(20, len(row), 7):
>   next = prefix + row[i:i+7]
>   # Handle 'next' - add it to the database or whateve
>
> Kent
>



-- 
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/b3ccec0f/attachment.htm 


More information about the Tutor mailing list