loads maci data from a file into any class/object

loading data from a file

Loads any plain text file that contains formatted maci data that follows the maci language syntax (See language), and loads the attribute names and data into a custom class/object. This is done in-place, so nothing is returned.

This can be very useful to load data back into an object whether already stored or after being stored to a file from the partner function maci.dump.

Basic Example of loading data from file into object using default positional parameters

maci.loadattrs('', my_object)

In this example, we simply load maci formatted data from a file using the loadattrs function and pass a string of the filepath to the file as the first argument to the function, then pass the custom object as the second argument to the function, and the data gets loaded into the object in-place.

Example data inside the file

mydata1 = 'data1'
mydata2 = 2

Access the data by their individual and respective attribute names like you normally would on an object in python.

Example accessing and viewing the data


parameters & arguments

Describes all parameter functionality and accepted data types

filename: str | Path

First required positional argument. Accepts strings and Path objects

Use this parameter to point to your filepath

class_object: ClassObject

Second required positional argument. Accepts any general custom object

Use this parameter to pass in your object to load data into it in-place

attr_name_dedup: bool

Optional parameter. Accepts booleans. Default = False

Use this parameter to enable/disable Attribute Name Deduplication. The default setting is disabled to loosen the constraints for your custom object data.

This feature protects against having duplicate attribute names loaded from a file. This is helpful if a name has already been defined in the file previously and you do not want it to be overwritten accidentally. This ensures attribute names are unique in your file especially when loading large data sets having thousands of names where it may be hard to keep track. You may enable this feature by setting this parameter to True if you need names to be protected, especially when they have already been defined in code. This really depends on your data to determine if this feature is beneficial to you.

encoding: str | None

Optional parameter. Accepts strings or None. Default = None

Use this parameter to load the data with the desired codec of the encoded data if needed. The default uses the default of python, so you don't have to use this, but you can if the data is using a specific codec.

_ignore_maci_attr_check: bool

Private optional parameter. Accepts booleans. Default = True

Use this parameter by setting it to False to disallow using matching names that maci object is already using. For example "_MaciDataObjConstructor__assignment_hard_locked_attribs".

It is not necessary to disable this unless you want to protect internal maci object names for some reason, because you are loading any potential names into your custom object, this is not something to be concerned about.

Last updated