I take it you are looking to store data from code onto disk for retrieval later with libraries external to Maya, or even outside of Maya.
2. Writing to disk.
Depending on your needs, you may not need serialization and can simply write data structures directly to disk; e.g. if you are looking to store text.
>> with open(file, 'w') as f:
>> f.write(my_text)
>>
>> with open(file, 'r') as f:
>> retrieved_text = f.read()
Serialization comes in many flavours and are relevant if you're looking to store more complex types, such as list, dict or arbitrary data structures of your own or Python's making.
The
shelve module as suggested above is appropriate if the data you're storing involves any objects other than the plain-old-data types, such as
string,
int,
bool etc.
If you're needs are simpler, an alternative to shelve is
json, also included in the standard library, but capable of storing only plain-old-data.
Both shelve and json come with their own writing mechanism, but in the case of json, the resulting serialized data is of type string and can be passed around and modified in code before being written out by other means.
>> serialized_data = json.dumps(my_data)
>> with open(file, 'w') as f:
>> f.write(serialized_data)
Which brings me to the next important topic of which json and shelve are good examples.
One results in human-readable data and the other does not. Generally, human-readable data lacks the performance of binary equivalents but make up for it in that they can be inspected and edited by humans. It all depends on your needs, really.
See here for a summary of what Python has to offer in this aspect