python readline from big text file -


when run this:

import os.path import pyproj srcproj = pyproj.proj(proj='longlat', ellps='grs80', datum='nad83') dstproj = pyproj.proj(proj='longlat', ellps='wgs84', datum='wgs84') f = file(os.path.join("distal-data", "countries.txt"), "r") heading = f.readline() # ignore field names. open('c:\python27\distal-data\geonames_20160222\countries.txt', 'r') f:            line in f.readlines():     parts = line.rstrip().split("|")     featurename = parts[1]     featureclass = parts[2]     lat = float(parts[9])     long = float(parts[10])     if featureclass == "populated place":       long,lat = pyproj.transform(srcproj, dstproj, long, lat)   f.close() 

i error:

file "c:\python27\importing world datacountriesfromnad83 towgs84.py", line 13, in line in f.readlines() : memoryerror.

i have downloaded countries file http://geonames.nga.mil/gns/html/namefiles.html entire country file dataset.

please me out of this.

readlines() large files creates large structure in memory, can try using:

f = open('somefilename','r') line in f:     dosomthing() 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -