Mercurial > hg > GlobalNeighbors
comparison globalneighbors/read.py @ 1:1b94f3bf97e5
* limit distance function
* start gridding
* improve unicode handling
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 14:02:14 -0700 |
parents | 5dba84370182 |
children | 7e27e874655b |
comparison
equal
deleted
inserted
replaced
0:5dba84370182 | 1:1b94f3bf97e5 |
---|---|
9 | 9 |
10 # TSV notes for python `csv` library: | 10 # TSV notes for python `csv` library: |
11 # https://stackoverflow.com/questions/15063936/csv-error-field-larger-than-field-limit-131072 | 11 # https://stackoverflow.com/questions/15063936/csv-error-field-larger-than-field-limit-131072 |
12 | 12 |
13 string = (str, basestring) | 13 string = (str, basestring) |
14 | |
14 | 15 |
15 def read_tsv_generator(f): | 16 def read_tsv_generator(f): |
16 """read tab-separated values from file `f` into memory""" | 17 """read tab-separated values from file `f` into memory""" |
17 | 18 |
18 reader = csv.reader(f, | 19 reader = csv.reader(f, |
41 if fields: | 42 if fields: |
42 cast = {key: value for key, value in cast.items() | 43 cast = {key: value for key, value in cast.items() |
43 if key in fields} | 44 if key in fields} |
44 yield cast | 45 yield cast |
45 | 46 |
47 | |
46 def read_city_list(f, fields=None, types=types): | 48 def read_city_list(f, fields=None, types=types): |
47 """read cities as a list""" | 49 """read cities as a list""" |
48 | 50 |
49 if isinstance(f, string): | 51 if isinstance(f, string): |
50 with open(f) as f_: | 52 with open(f) as f_: |