MMpy.filetools.read_all

Syntax

MMpy.filetools.read_all(file_name, directory=None, fields=None, as_type=''auto'')

Description

Read all rows from a data file.

Parameters

Name
Type
Description

file_name

string

The name and extension of the file to open.

directory

string (optional)

The path to the directory that contains file_name. Defaults to MMpy.Project.path()

fields

A list of strings (optional)

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

as_type

string

One of ‘auto’, ‘dict’, or ‘df’. Determines if the return value should be a dictionary or a pandas.DataFrame (if pandas is available). Defaults to ‘'auto’'.

Returns

Type
Description

list[dict] or pandas.DataFrame

A list of dictionaries per row or a pandas.DataFrame

Notes

pandas.DataFrame output requires the third part module, pandas. See the Script Editor help for further information regarding installation of third party modules.

If as_type='df' is specified a ValueError is raised if pandas cannot be imported.

Examples

# reads all fields from MMpy.Project.path() + some_file.DAT into a 
# DataFrame if pandas is installed by the user, or a dict
data = MMpy.filetools.read_all('some_file.DAT')

# outputs a list[dict[str, Any]] from the explicit path + file, in the form
# [
# { 'EAST': 0, 'NORTH': 0, 'RL': 0 }, # first row
# ...
# { 'EAST': 0, 'NORTH': 0, 'RL': 0 }, # last row
# ]
data = MMpy.filetools.read_all(
  'another_file.DAT', 'C:\\path\\to\\file', ['EAST', 'NORTH', 'RL'], as_typ='dict')

Resource ID

IDPH_FILETOOLS_READ_ALL