MMpy.filetools.RowReader

Syntax

MMpy.filetools.RowReader(file, fields=None)

Description

Provide a means to read the rows in a data file using a Python for loop.

Parameters

Name
Type
Description

file

MMpy.File

An open data file.

fields

list of strings (optional)

If not None, the columns whose names are specified in fields will be included in the output.

Returns

Type
Description

dict

Yields a dictionary for each row in the data file.

Notes

The values are read-only.

See Also

MMpy.filetools.read_all()

MMpy.filetools.write_all()

MMpy.filetools.Writer

Examples

from MMpy.filetools import ContextManager, RowReader with ContextManager('some_file.DAT') as file1: # create the iterator, only reading the EAST, NORTH and RL fields rows = RowReader(file1, ['EAST', 'NORTH', 'RL']) for row in rows: for field, value in row.items(): # do something with each field-value pair continue with ContextManager('another_file.DAT') as file2: # use the Python built-in enumerate to count rows for i, row in enumerate(RowReader(file2)): # row is a dictionary for the i-th row print(f"Row {i+1} = {row}")

Resource ID

IDPH_FILETOOLS_ROW_READER