[Chicago] Using split to arrays

Freddy Martinez freddymartinez9 at gmail.com
Mon Mar 12 17:37:21 CET 2012


Greetings ChiPy,

I'm having an issue reading a file into two arrays (or one
multi-dimensional array):

The file is formatted like this (a simple comma delimited text file).

09:30:17,100,120.42,,
09:30:31,600,120.31,100,
09:30:37,600,120.31,,
09:30:47,500,120.3,,
09:30:50,100,120.3,,
09:30:50,100,120.2985,,

I need each data field to be its own array element. (which is where
I'm having a problem).  I can read each in line and create a list
array, but I can't use the split function on a list array.

The code is as follows:

import csv
import collections
d = collections.defaultdict(int)
execution=[]
details=[]
data=[]

marguse=0
avlmargin=0

execution=open('/home/freddy/Margin2.txt'.strip(),'r')

for line in execution:
    linedat=line.strip().split(",")
    details.append(linedat)

print details[0]

The code output is as such: ['09:30:17', '100', '120.42', '', ''] but
it is a an array of lists. I'm trying to figure out the best way to
iterate through the execution array and create another array. I'm
fairly sure its the way I am opening and reading the file but I'm not
sure.

Ideas?

Thanks in advance.

Freddy


More information about the Chicago mailing list