Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'yet.': 0.04; 'converts': 0.09; 'data:': 0.09; 'python': 0.11; 'wrote': 0.14; '>in': 0.16; '>to': 0.16; 'csv': 0.16; 'etc...': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'modules,': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'skip:> 20': 0.16; 'subject:CSV': 0.16; 'usable': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'normally': 0.19; 'shape': 0.19; "skip:' 30": 0.19; 'example': 0.22; 'header:User-Agent:1': 0.23; 'cheers,': 0.24; 'file.': 0.24; "i've": 0.25; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; '(this': 0.29; 'question:': 0.31; 'way?': 0.31; 'file': 0.32; 'there.': 0.32; 'regular': 0.32; 'proceed': 0.33; 'reader': 0.33; '"the': 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'i.e.': 0.36; 'received:com.au': 0.36; 'skip:> 10': 0.36; 'charset:us-ascii': 0.36; 'too': 0.37; 'received:211': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'back': 0.62; 'content-disposition:inline': 0.62; 'more': 0.64; 'export': 0.74; 'analysis': 0.75; 'as:': 0.81 Date: Sun, 14 Sep 2014 18:38:41 +1000 From: Cameron Simpson To: python-list@python.org Subject: Re: CSV methodology MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) References: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=fvDlOjIf c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=LcaDllckn3IA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=M3_lF8AQAAAA:8 a=QjwWv4ekSnfnV4r1tokA:9 a=CjuIK1q_8ugA:10 a=nd4EZRjL5cAA:10 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410683932 news.xs4all.nl 2850 [2001:888:2000:d::a6]:48341 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77862 On 13Sep2014 21:34, jetrn@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 For a good prime, call: 391581 * 2^216193 -1