Huge file handling and sorting using python -


im working on program uses file having data in format - 6 columns , dynamic no. of rows.

the file got testing 26 mb , following program converts first 3 columns 3 different lists.

f = open('foo', 'r') print('running...') = [] b = [] c = [] line in f:     x = (line.split(' '))     a.append(x[0])     b.append(x[1])     c.append(x[2]) print(a,b,c,sep='\n') 

i have rechecked program , logic looks correct , when implemented on small file works when use program 26 mb file stops responding.

description of program: program opens file name 'foo' , implements line line of file. splits line parts based on separator defined argument in .split() method. in program have used white space separator in text file data separated using white spaces.

im not able figure out why program stops responding , need it!

if use numpy, can use genfromtxt:

import numpy np  a,b,c=np.genfromtxt('foo',usecols=[0,1,2],unpack=true) 

does work large file?

edit:

ok, tried on file, , seems work fine. i'm not sure problem is.

in [1]: numpy import genfromtxt  in [2]: a,b,c=genfromtxt('foo',usecols=[0,1,2],unpack=true)  in [3]: out[3]:  array([ 406.954744,  406.828508,  406.906079, ...,  408.944226,         408.833872,  408.788698])  in [4]: b out[4]:  array([ 261.445358,  261.454366,  261.602131, ...,  260.46189 ,         260.252377,  260.650606])  in [5]: c out[5]:  array([ 17.451789,  17.582017,  17.388673, ...,  26.41099 ,  26.481148,         26.606282])  in [6]: print len(a), len(b), len(c) 419040 419040 419040 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -