CSV methodology
Dave Angel
davea at davea.name
Mon Sep 15 09:29:48 EDT 2014
jetrn at newsguy.com Wrote in message:
>
> Hello. Back in the '80s, I wrote a fractal generator, which, over the years,
> I've modified/etc to run under Windows. I've been an Assembly Language
> programmer for decades. Recently, I decided to learn a new language,
> and decided on Python, and I just love it, and the various IDEs.
>
> 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:
>
> -----------------------------------------------
> 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.
>
>
Looks to me like your MXP has produced a single line file, with
all the values on that single line separated by commas. If the
data is really uniform, then it'd be more customary to put one
item per line. But your sample seems to imply the data is a float
followed by 3 ints. If so, then I'd expect to see a line for each
group of 4.
The only advantage of a csv is if the data is rectangular. If
it's really a single column, it should be one per line, and
you'd use readline instead.
--
DaveA
More information about the Python-list
mailing list