Skip to main content

Easily save and load any object data to/from a xml file

Project description

EZobject2xml

Save and load easily any python object data into/from a xml file.

This module has only one object xmltool with 2 functions.

For saving an object into a xml file, you just have to code (python):

from EZobject2xml.xmltoolMod import *
myXmltool = xmltool()
myXmltool.saveObject2xml(myObject,myFilename)

where:

myObject is the object to save

myFileName if the xml file

And for loading:

myXmltool.loadObjectFromXml(myObject,myFilename)

Not wanna save a data of your object ?:

Just add "__" at the end of the name of the data and "saveObject2xml" function won't save this data.

Wanna save a single value data such as integer, float, string, set, tuple, list or dict ?:

You just have to use SingleType class object:

from EZobject2xml.xmltoolMod import *
myxmltool = xmltool()
myvalue_object = SingleType(myvalue)
myxmltool.saveObject2xml(myvalue_object,'myvalue.xml')

For loading:

myxmltool.loadObjectFromXml(myvalue_object,'myvalue.xml')
myvalue = myvalue_object.value

where:

myvalue is any basic data type as int, float, str, set, tuple, list or dict

Exception:

If objects have to be dynamically initialized during the data reading process (i.e. if your object has a list of an undefined number of other objects), we have to create them first before reading their saved data. In order to do that, we give a list of object class that we could use to create a new instance of these objects.

This list of class objects is a initDataList object and we pass it as:

myInitDataList = initDataList()
myInitDataList.addInitData(mySubObject1Class,(a tuple containing the parameters to initialize this SubObject))
myInitDataList.addInitData(mySubObject2Class,(a tuple containing the parameters to initialize this SubObject))
...

myXmltool = xmltool()
myXmltool.loadObjectFromXml(myObject,myFilename,myInitDataList)

where:

mySubObject1Class is the class of an object which can be contained in myObject

myObject is the object to save

myFileName if the xml file

As seen, myInitDataList is optional and only needed when your object has a list of an undefined number of other objects.

The test file has a concrete example.

Please see the python help() function to see more technical information about these functions.

To install the package :

-m pip install EZobject2xml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EZobject2xml-1.0.2.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

EZobject2xml-1.0.2-py3-none-any.whl (7.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page