CSV methodology
Cameron Simpson
cs at zip.com.au
Sun Sep 14 04:38:41 EDT 2014
More information about the Python-list mailing list
Sun Sep 14 04:38:41 EDT 2014
- Previous message (by thread): CSV methodology
- Next message (by thread): CSV methodology
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 13Sep2014 21:34, jetrn at newsguy.com <jetrn at newsguy.com> wrote: >Hello. Back in the '80s, I wrote a fractal generator, [...] >Anyway, something I thought would be interesting, would be to export >some data from my fractal program (I call it MXP), and write something >in Python and its various scientific data analysis and plotting modules, >and... well, see what's in there. > >An example of the data: >1.850358651774470E-0002 >32 >22 >27 >... (this format repeats) > >So, I wrote a procedure in MXP which converts "the data" and exports >a csv file. So far, here's what I've started with: Normally a CSV file will have multiple values per row. Echoing Terry, what shape did you intend your CSV data to be? i.e. what values appear on a row? >import csv >fname = 'E:/Users/jayte/Documents/Python Scripts/XportTestBlock.csv' >f = open(fname) >reader = csv.reader(f) >for flt in reader: > x = len(flt) >file.close(f) > >This will get me an addressable array, as: > >flt[0], flt[1], flt[350], etc... from which values can be assigned to >other variables, converted... > >My question: Is there a better way? Do I need to learn more about >how csv file are organized? Perhaps I know far too little of Python >to be attempting something like this, just yet. If you have a nice regular CSV file, with say 3 values per row, you can go: reader = csv.reader(f) for row in reader: a, b, c - row and proceed with a, b and c directly from there. But of course, that requires your export format to be usable that way. Cheers, Cameron Simpson <cs at zip.com.au> For a good prime, call: 391581 * 2^216193 -1
- Previous message (by thread): CSV methodology
- Next message (by thread): CSV methodology
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list