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.

This is usually a two-step process:
1. Serialization <http://en.wikipedia.org/wiki/Serialization>, which means
to make a set of data - in this case, internal to Python - writeable to
disk and retrievable later.
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 <http://docs.python.org/2/library/shelve.html> 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<http://docs.python.org/2/library/json.html>,
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
http://docs.python.org/2/library/persistence.html



On 4 February 2014 05:48, Chad Dombrova <[email protected]> wrote:

> I *think* that Glom was looking for something similar to optionVars for
> use outside of Maya, but I could be wrong.
> —
> Sent from Mailbox <https://www.dropbox.com/mailbox> for iPhone
>
>
> On Mon, Feb 3, 2014 at 8:43 PM, Count Zer0 <[email protected]> wrote:
>
>> PyMel gives you easy access to them too:
>>
>>
>> http://download.autodesk.com/global/docs/maya2013/en_us/PyMel/generated/classes/pymel.core.language/pymel.core.language.OptionVarDict.html
>>
>> And you should be using PyMel anyway if you're moving past MEL anyway.
>>
>> -jason
>>
>> On Monday, February 3, 2014 9:21:44 AM UTC-8, Glom De wrote:
>>>
>>> hi guys
>>> as you know ,maya command "optionVar"  can store variables in disk,
>>> are there any functions or Module of python can do same thing like Maya
>>> cmd "optionVar"
>>>
>>> googled , but did not find any clue。。。。。
>>> anyone can give me some info about that, thanks a lot!!!
>>>
>>   --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/1cf36bfc-4066-4a6c-acd0-860ecd33b765%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/1391492891930.317b607f%40Nodemailer
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
*Marcus Ottosson*
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAAepsjw_wDVgOF5yDbP5Mn9MOtUrVtNMFNktbzQ_cAcw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to