Python Dict date save on the Attribute of node

95 views
Skip to first unread message

miarmy

unread,
Apr 28, 2018, 5:34:22 AM4/28/18
to Python Programming for Autodesk Maya
Hi....i have a python dict...
I want write it on the attribue of my node or read...
Now, which attr type to choose for my node?
I test this type:
#attr type:
Om.MFnTypedAttribute().create('test','t', Om.MFnData.kString)
...
For write or save dict on the node...i convert the dict to string and save it.and when iitant to read.... I use eval() function:
dict = eval(string)
But eval function is very very slow....in the big dict or string...
One point... My dict have only float number.. this form:.{1:[2,4.5], 4:[6,9.2], ... }
Excuse me.my english is bad

Justin Israel

unread,
Apr 28, 2018, 5:38:55 AM4/28/18
to python_in...@googlegroups.com
Hi, 

Avoid using the string representation of a dict and eval(). Instead, encode it to either json or python specific cPickle



For pickle, you can use the protocol 0 which is the ascii format. 

Justin 


--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b010424c-6238-487a-9e7e-f9d6fabd22c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Apr 28, 2018, 8:09:40 PM4/28/18
to python_in...@googlegroups.com

On 28 April 2018 at 18:38, Justin Israel <justin...@gmail.com> wrote:
Hi, 

Avoid using the string representation of a dict and eval(). Instead, encode it to either json or python specific cPickle



For pickle, you can use the protocol 0 which is the ascii format. 

Justin 
On Sat, Apr 28, 2018, 9:34 PM miarmy <egol...@gmail.com> wrote:
Hi....i have a python dict...
I want write it on the attribue of my node or read...
Now, which attr type to choose for my node? 
I test this type:
#attr type:
Om.MFnTypedAttribute().create('test','t', Om.MFnData.kString)
...
For write or save dict on the node...i convert the dict to string and save it.and when iitant to read.... I use eval() function:
dict = eval(string)
But eval function is very very slow....in the big dict or string...
One point... My dict have only float number.. this form:.{1:[2,4.5], 4:[6,9.2], ... }
Excuse me.my english is bad

--
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 python_inside_maya+unsub...@googlegroups.com.

--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA31J9%3DPj0zFD%3D90SQSz3bJoPO489zfRcPPKBA-6acDrRQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages