# maci.loadattrs

### loading data from a file

Loads any plain text file that contains formatted maci data that follows the maci language syntax (See [language](/docs/maci/language.md)), 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](broken://pages/iDpQZ6gfz5ySQsP0QjXW).

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

```python
maci.loadattrs('my.data', 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.&#x20;

*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*

```python
my_object.mydata1
my_object.mydata2
print(my_object.mydata1)
print(my_object.mydata2)
```

### parameters & arguments

Describes all parameter functionality and accepted data types

<details>

<summary>filename:  str | Path</summary>

First required positional argument. Accepts strings and [Path objects](https://docs.python.org/3/library/pathlib.html)

Use this parameter to point to your filepath

</details>

<details>

<summary>class_object:  ClassObject</summary>

Second required positional argument. Accepts any general custom object

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

</details>

<details>

<summary>attr_name_dedup:  bool</summary>

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.&#x20;

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.

</details>

<details>

<summary>encoding:  str | None</summary>

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.

</details>

<details>

<summary>_ignore_maci_attr_check:  bool</summary>

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".&#x20;

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.&#x20;

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.macilib.org/docs/maci/functions/maci.loadattrs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
