Containers#
The role of a Container
is to describe the structure of one or more
memory areas in a data source.
A container always needs one or more fields to describe the content of the memory area.
Overview#
The list below shows the available container classes.
View Field Attributes#
A container can view the attributes of each field
nested in the container by calling its method
view_fields()
.
The default attribute is the field value
.
>>> # Create an empty container.
>>> container = Container()
>>> # View the field values in the container.
>>> container.view_fields()
View as a JSON String#
A container can view the attributes of each field
nested in the container as a JSON formatted string by calling its
method to_json()
.
The default attribute is the field value
.
>>> container.to_json()
'null'
List Field Items#
A container can list all its field items nested in the
container as a flatten list in the form of ('field path', field item)
tuples by calling its method field_items()
.
>>> # List the field items in the container.
>>> container.field_items()
[]
List Field Attributes#
A container can list the attributes of each field item
nested in the container as a flatten list in the form of
('field path', attribute)
or ('field path', list(attributes))
tuples by
calling its method to_list()
.
The default attribute is the field value
.
>>> # List the field values in the container.
>>> container.to_list()
[]
A container can list the attributes of each field item
nested in the container as a flatten dictionary in the form of
{'field path': attribute}
or {'field path': list(attributes)}
pairs
by calling its method to_dict()
.
The default attribute is the field value
.
>>> # List the field values in the container.
>>> container.to_dict()
{'Container': {}}
A container can list the attributes of each field item
nested in the container as a flatten list of dictionaries containing
the field path and the selected field attributes by calling its method
to_csv()
.
The default attribute is the field value
.
>>> # List the field values in the container.
>>> container.to_csv()
[]
Note
The class name of the instance is used for the root name as long as no name is given.
Write Field Attributes#
A container can write the attributes of each field item
nested in the container to a .json
file by calling its method
write_json()
.
The default attribute is the field value
.
>>> # Save the field values to a '.json' file.
>>> container.write_json("./_static/container.json")
The generated .json
file for the container looks like this:
null
A container can write the attributes of each field item
nested in the container to a .csv
file by calling its method
write_csv()
.
The default attribute is the field value
.
>>> # Save the field values to a '.csv' file.
>>> container.write_csv("./_static/container.csv")
The generated .csv
file for the container looks like this:
id,value
Note
The class name of the instance is used for the root name as long as no name is given.
Save Field Attributes#
A container can save the attributes of each field item
nested in the container to an .ini
file by calling its method
save()
.
The default attribute is the field value
.
>>> # Save the field values to an '.ini' file.
>>> container.save("./_static/container.ini")
The generated .ini
file for the container looks like this:
[Container]
Note
The class name of the instance is used for the section name as long as no section is given.
Load Field Values#
A container can load the value of each field item
nested in the container from an .ini
file by calling its method
load()
.
>>> # Load the field values from an '.ini' file.
>>> container.load("./_static/container.ini")
[Container]
Note
The class name of the instance is used for the section name as long as no section is given.