@@ -382,7 +382,6 @@ def init_table(self, table_name, fields, line_num):
382
382
:param line_num: line number of the table's header (its name)
383
383
:returns: final name for the new table
384
384
"""
385
-
386
385
if table_name not in self ._table_count :
387
386
self ._table_count [table_name ] = 1
388
387
else :
@@ -402,6 +401,39 @@ def init_table(self, table_name, fields, line_num):
402
401
403
402
return table_name
404
403
404
+ def get_value (self , table , field = None , index = None ):
405
+ """
406
+ Get value from table field.
407
+
408
+ :param table: table name
409
+ :param field: field name
410
+ :returns: value in the extcsv file.
411
+ """
412
+ if table not in self .extcsv :
413
+ raise KeyError (f"Table '{ table } ' not found in extcsv." )
414
+
415
+ if field is not None and field not in self .extcsv [table ]:
416
+ raise KeyError (f"Field '{ field } ' not found in table '{ table } '." )
417
+
418
+ headers = [
419
+ 'CONTENT' , 'DATA_GENERATION' , 'PLATFORM' ,
420
+ 'INSTRUMENT' , 'LOCATION' , 'TIMESTAMP'
421
+ ]
422
+
423
+ if index == 1 :
424
+ return self .extcsv [table ][field ][0 ]
425
+
426
+ if table in headers and field is None :
427
+ data = self .extcsv [table ]
428
+ for field in list (data .keys ()):
429
+ if field != 'comments' and isinstance (data [field ], list ):
430
+ data [field ] = data [field ][0 ]
431
+ return data
432
+ elif table not in headers and field is None :
433
+ return self .extcsv [table ]
434
+
435
+ return self .extcsv [table ][field ]
436
+
405
437
def add_field_to_table (self , table_name , fields , index = 1 ):
406
438
"""
407
439
Record an empty column(s) in Extended CSV table named <table_name>
0 commit comments