Changeset 7854 for trunk/anuga_core/source/anuga/file/csv_file.py
- Timestamp:
- Jun 17, 2010, 4:48:21 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/file/csv_file.py
r7780 r7854 15 15 16 16 17 def load_csv_as_dict(file_name, title_check_list=None, delimiter=','): 17 def load_csv_as_dict(file_name, title_check_list=None, delimiter=',', 18 d_type = str): 18 19 """ 19 20 Load in the csv as a dictionary, title as key and column info as value. … … 26 27 27 28 delimiter is the delimiter used to separate the fields 29 30 format is one of float, str, int 28 31 29 32 return 2 dictionaries: ({key:column}, {title:index}). … … 35 38 36 39 # FIXME(Ole): Consider dealing with files without headers 37 # FIXME(Ole): Consider a wrapper automatically converting text fields38 # to the right type by trying for: int, float, string39 40 40 41 attribute_dic = {} … … 67 68 msg += 'although there were %d headers' % title_count 68 69 raise IOError, msg 69 for i, val uein enumerate(line[:title_count]): # skip trailing data70 attribute_dic.setdefault(titles_stripped[i], []).append( value)70 for i, val in enumerate(line[:title_count]): # skip trailing data 71 attribute_dic.setdefault(titles_stripped[i], []).append(d_type(val)) 71 72 72 73 return attribute_dic, title_index_dic
Note: See TracChangeset
for help on using the changeset viewer.