No, there isn’t a datatype for dictionaries.
Converting to string via json.dumps()
is one way, you can also convert to a more compact string via something like cPickle.dumps(my_dict)
, or compress it to e.g. zip
and then dumps
it, but as far as Maya is concerned they are all of type string. Odds are you can convert it into any of the other available types, like a huge number, but string isn’t a bad option; it’s got no size limit (other than your total amount of RAM and disk space) and probably isn’t posing any relevant performance overhead on its own in terms of reading and writing to the attribute. The conversion between Maya and Python can however be costly, and pickle is likely the faster option in this case (depending on your data). The only thing to look out for with that is that it will limit the result to machine-readable output (e.g. Xz\939150\0klk5
) and furthermore only be readable by the particular version of Python you are running at the time of performing the dump. That is, if you store a dumped pickle in Maya 2013 on Linux, odds are you can’t read it in 2018 on Windows (or even the same version of Maya but on different OSes) etc. On the other hand, you can pickle more than just dictionaries. Whole classes and instanced PyMel nodes and what else have you.
You can see what Maya types are available as extra (i.e. “dynamic”) attributes here for example.
No, there isn’t a datatype for dictionaries.
Converting to string via
json.dumps()
is one way, you can also convert to a more compact string via something likecPickle.dumps(my_dict)
, or compress it to e.g.zip
and thendumps
it, but as far as Maya is concerned they are all of type string. Odds are you can convert it into any of the other available types, like a huge number, but string isn’t a bad option; it’s got no size limit (other than your total amount of RAM and disk space) and probably isn’t posing any relevant performance overhead on its own in terms of reading and writing to the attribute. The conversion between Maya and Python can however be costly, and pickle is likely the faster option in this case (depending on your data). The only thing to look out for with that is that it will limit the result to machine-readable output (e.g.Xz\939150\0klk5
) and furthermore only be readable by the particular version of Python you are running at the time of performing the dump. That is, if you store a dumped pickle in Maya 2013 on Linux, odds are you can’t read it in 2018 on Windows (or even the same version of Maya but on different OSes) etc.
On the other hand, you can pickle more than just dictionaries. Whole classes and instanced PyMel nodes and what else have you.
You can see what Maya types are available as extra (i.e. “dynamic”) attributes here for example.
--
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/CAFRtmOA3GN9tH%3Dz13BwwVQo35fzkv63-c4iM3xuuSsmZxJ5f%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
then it should be able to be dumped on Maya 2013 in Linux and read in Maya 2018 on Windows.
TLDR; compiler differences and unavailable internal datastructures.
For starters, one thing that could be confusing is how there is pickle
and then there is cPickle
. pickle
is a pure Python library which I expect have no trouble with cross-platform compatibility. cPickle
on the other hand is a compiled library and, like anything compiled, I’d expect the same incompatibility as with it as with e.g. PyQt unless it’s compiled for the particular version of Maya’s Python interpreter, and the same for NumPy and friends. (Can this be not true?)
However aside from that, with both pickle
and cPickle
you are still serialising internal data structures and not all datastructures on Linux are available on Windows, not all in Maya 2013 are available in Maya 2018. In the simplest case of incompatibility, you could pickle a PyMEL object in Maya 2018 that hasn’t yet been invented in 2013, or a MASH
object that didn’t exist in 2013. Or pickle some instance of one of your own plug-ins, that you’ve got a different version of on another computer.
I would think that the only way to be safe in a multi-OS, multi-Maya environment, is to both stick with pickle
(not cPickle
) and ensure your data is JSON-serialisable to begin with (no complex data). But in that case, you’ve run out of reasons to use pickle over json anyway.
Taking a closer look at the documentation, I also spotted..
The pickle serialization format is guaranteed to be backwards compatible across Python releases.
Which I would read “data pickled in Maya 2013 is guaranteed to be compatible with Maya 2018”, but not the other way around (that would be forwards compatibility). This, I think, would invalidate even the “safe” option I listed just now.
With all this said, I did expect to find larger warning signs explicitly written out in both the Python docs and community, but can’t seem to find a conclusive answer. So with that in mind, I’ll change my position from “Odds are you will run into trouble” to “Odds are you may run into trouble”. Would you agree?
On Sat, Mar 3, 2018, 5:52 AM Marcus Ottosson <konstr...@gmail.com> wrote:No, there isn’t a datatype for dictionaries.
Converting to string via
json.dumps()
is one way, you can also convert to a more compact string via something likecPickle.dumps(my_dict)
, or compress it to e.g.zip
and thendumps
it, but as far as Maya is concerned they are all of type string. Odds are you can convert it into any of the other available types, like a huge number, but string isn’t a bad option; it’s got no size limit (other than your total amount of RAM and disk space) and probably isn’t posing any relevant performance overhead on its own in terms of reading and writing to the attribute. The conversion between Maya and Python can however be costly, and pickle is likely the faster option in this case (depending on your data). The only thing to look out for with that is that it will limit the result to machine-readable output (e.g.Xz\939150\0klk5
) and furthermore only be readable by the particular version of Python you are running at the time of performing the dump. That is, if you store a dumped pickle in Maya 2013 on Linux, odds are you can’t read it in 2018 on Windows (or even the same version of Maya but on different OSes) etc.Why would that be true? If you specify the protocol when you read and write the cPickle data, then it should be able to be dumped on Maya 2013 in Linux and read in Maya 2018 on Windows.One could stick with binary protocol 2 the whole way through, I would think. Am I wrong?
--On the other hand, you can pickle more than just dictionaries. Whole classes and instanced PyMel nodes and what else have you.
You can see what Maya types are available as extra (i.e. “dynamic”) attributes here for example.
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/CAFRtmOA3GN9tH%3Dz13BwwVQo35fzkv63-c4iM3xuuSsmZxJ5f%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/CAPGFgA38%2BW2k7W1bpMYsnnincG9S%2BgS2uW9Fknh5rCpnYHuFtA%40mail.gmail.com.
then it should be able to be dumped on Maya 2013 in Linux and read in Maya 2018 on Windows.
TLDR; compiler differences and unavailable internal datastructures.
For starters, one thing that could be confusing is how there is
pickle
and then there iscPickle
.pickle
is a pure Python library which I expect have no trouble with cross-platform compatibility.cPickle
on the other hand is a compiled library and, like anything compiled, I’d expect the same incompatibility as with it as with e.g. PyQt unless it’s compiled for the particular version of Maya’s Python interpreter, and the same for NumPy and friends. (Can this be not true?)However aside from that, with both
pickle
andcPickle
you are still serialising internal data structures and not all datastructures on Linux are available on Windows, not all in Maya 2013 are available in Maya 2018. In the simplest case of incompatibility, you could pickle a PyMEL object in Maya 2018 that hasn’t yet been invented in 2013, or aMASH
object that didn’t exist in 2013. Or pickle some instance of one of your own plug-ins, that you’ve got a different version of on another computer.I would think that the only way to be safe in a multi-OS, multi-Maya environment, is to both stick with
pickle
(notcPickle
) and ensure your data is JSON-serialisable to begin with (no complex data). But in that case, you’ve run out of reasons to use pickle over json anyway.Taking a closer look at the documentation, I also spotted..
The pickle serialization format is guaranteed to be backwards compatible across Python releases.
Which I would read “data pickled in Maya 2013 is guaranteed to be compatible with Maya 2018”, but not the other way around (that would be forwards compatibility). This, I think, would invalidate even the “safe” option I listed just now.
With all this said, I did expect to find larger warning signs explicitly written out in both the Python docs and community, but can’t seem to find a conclusive answer. So with that in mind, I’ll change my position from “Odds are you will run into trouble” to “Odds are you may run into trouble”. Would you agree?
On 2 March 2018 at 20:54, Justin Israel <justin...@gmail.com> wrote:
On Sat, Mar 3, 2018, 5:52 AM Marcus Ottosson <konstr...@gmail.com> wrote:No, there isn’t a datatype for dictionaries.
Converting to string via
json.dumps()
is one way, you can also convert to a more compact string via something likecPickle.dumps(my_dict)
, or compress it to e.g.zip
and thendumps
it, but as far as Maya is concerned they are all of type string. Odds are you can convert it into any of the other available types, like a huge number, but string isn’t a bad option; it’s got no size limit (other than your total amount of RAM and disk space) and probably isn’t posing any relevant performance overhead on its own in terms of reading and writing to the attribute. The conversion between Maya and Python can however be costly, and pickle is likely the faster option in this case (depending on your data). The only thing to look out for with that is that it will limit the result to machine-readable output (e.g.Xz\939150\0klk5
) and furthermore only be readable by the particular version of Python you are running at the time of performing the dump. That is, if you store a dumped pickle in Maya 2013 on Linux, odds are you can’t read it in 2018 on Windows (or even the same version of Maya but on different OSes) etc.Why would that be true? If you specify the protocol when you read and write the cPickle data, then it should be able to be dumped on Maya 2013 in Linux and read in Maya 2018 on Windows.One could stick with binary protocol 2 the whole way through, I would think. Am I wrong?
--On the other hand, you can pickle more than just dictionaries. Whole classes and instanced PyMel nodes and what else have you.
You can see what Maya types are available as extra (i.e. “dynamic”) attributes here for example.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA3GN9tH%3Dz13BwwVQo35fzkv63-c4iM3xuuSsmZxJ5f%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA38%2BW2k7W1bpMYsnnincG9S%2BgS2uW9Fknh5rCpnYHuFtA%40mail.gmail.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/CAFRtmODAvy8To4jCAk-n%3DvffzPFKGLiQu%2B19RCgapnLG%2BF%3DBKw%40mail.gmail.com.
then it should be able to be dumped on Maya 2013 in Linux and read in Maya 2018 on Windows.
TLDR; compiler differences and unavailable internal datastructures.
For starters, one thing that could be confusing is how there is
pickle
and then there iscPickle
.pickle
is a pure Python library which I expect have no trouble with cross-platform compatibility.cPickle
on the other hand is a compiled library and, like anything compiled, I’d expect the same incompatibility as with it as with e.g. PyQt unless it’s compiled for the particular version of Maya’s Python interpreter, and the same for NumPy and friends. (Can this be not true?)However aside from that, with both
pickle
andcPickle
you are still serialising internal data structures and not all datastructures on Linux are available on Windows, not all in Maya 2013 are available in Maya 2018. In the simplest case of incompatibility, you could pickle a PyMEL object in Maya 2018 that hasn’t yet been invented in 2013, or aMASH
object that didn’t exist in 2013. Or pickle some instance of one of your own plug-ins, that you’ve got a different version of on another computer.I would think that the only way to be safe in a multi-OS, multi-Maya environment, is to both stick with
pickle
(notcPickle
) and ensure your data is JSON-serialisable to begin with (no complex data). But in that case, you’ve run out of reasons to use pickle over json anyway.Taking a closer look at the documentation, I also spotted..
The pickle serialization format is guaranteed to be backwards compatible across Python releases.
Which I would read “data pickled in Maya 2013 is guaranteed to be compatible with Maya 2018”, but not the other way around (that would be forwards compatibility). This, I think, would invalidate even the “safe” option I listed just now.
With all this said, I did expect to find larger warning signs explicitly written out in both the Python docs and community, but can’t seem to find a conclusive answer. So with that in mind, I’ll change my position from “Odds are you will run into trouble” to “Odds are you may run into trouble”. Would you agree?
On 2 March 2018 at 20:54, Justin Israel <justin...@gmail.com> wrote:
On Sat, Mar 3, 2018, 5:52 AM Marcus Ottosson <konstr...@gmail.com> wrote:No, there isn’t a datatype for dictionaries.
Converting to string via
json.dumps()
is one way, you can also convert to a more compact string via something likecPickle.dumps(my_dict)
, or compress it to e.g.zip
and thendumps
it, but as far as Maya is concerned they are all of type string. Odds are you can convert it into any of the other available types, like a huge number, but string isn’t a bad option; it’s got no size limit (other than your total amount of RAM and disk space) and probably isn’t posing any relevant performance overhead on its own in terms of reading and writing to the attribute. The conversion between Maya and Python can however be costly, and pickle is likely the faster option in this case (depending on your data). The only thing to look out for with that is that it will limit the result to machine-readable output (e.g.Xz\939150\0klk5
) and furthermore only be readable by the particular version of Python you are running at the time of performing the dump. That is, if you store a dumped pickle in Maya 2013 on Linux, odds are you can’t read it in 2018 on Windows (or even the same version of Maya but on different OSes) etc.Why would that be true? If you specify the protocol when you read and write the cPickle data, then it should be able to be dumped on Maya 2013 in Linux and read in Maya 2018 on Windows.One could stick with binary protocol 2 the whole way through, I would think. Am I wrong?
--On the other hand, you can pickle more than just dictionaries. Whole classes and instanced PyMel nodes and what else have you.
You can see what Maya types are available as extra (i.e. “dynamic”) attributes here for example.
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/CAFRtmOA3GN9tH%3Dz13BwwVQo35fzkv63-c4iM3xuuSsmZxJ5f%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/CAPGFgA38%2BW2k7W1bpMYsnnincG9S%2BgS2uW9Fknh5rCpnYHuFtA%40mail.gmail.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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODAvy8To4jCAk-n%3DvffzPFKGLiQu%2B19RCgapnLG%2BF%3DBKw%40mail.gmail.com.
Yes, that would make sense. It’d be like how mayaAscii
and mayaBinary
are plain-text and binary respectively, but still equally compatible with Maya, regardless of platform.
Perhaps it’s then safe to surmise that because pickle
is spelled out as being cross-platform compatible, and cPickle
is compatible with anything coming out of pickle
, then anything coming out of cPickle
is also cross-platform compatible. Especially when considering this line.
The data streams the two modules produce are guaranteed to be interchangeable.
To the original question, I had another idea that might prove useful.
The goal is to embed a dictionary - i.e. nested - datastructure in Maya, and one way of doing so is to take a Python dictionary, convert it to a string and store it in a Maya string plug.
However, what if you were to consider Maya’s plugs as key/value pairs, where the attribute name is the key, and its value is.. well, the value? In that case, you could either:
cmds.getAttr("myNode.key")
cmds.getAttr("myNode.myCompound")
is similar to what you would normally get out of a dictionary.data = {
"project": "Avengers",
"shot": "0050",
"task": "animation",
"started": True
}
cmds.getAttr("myNode.myCompound.project") == u"Avengers"
cmds.getAttr("myNode.myCompound.shot") == u"0050"
cmds.getAttr("myNode.myCompound.started") == True
It’d even get you all attributes at once if you ask nicely.
cmds.getAttr("myNode.myCompound") == (u"Avengers", u"0050", u"animation", True)
However probably not in the order of your original dictionary, and without the actual keys. That said, the order is reliable, as it would be in the order that the attributes were added, so you may be able to determine the key separate from your query. Note that this would also work with nested compound attributes, and more datatypes than would otherwise be supported by JSON, e.g. long
, double3
, mesh
and nurbsCurve
data.
So in this case, then Yes, you can embed a dictionary. :)
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/CAFRtmOA3GN9tH%3Dz13BwwVQo35fzkv63-c4iM3xuuSsmZxJ5f%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/CAPGFgA38%2BW2k7W1bpMYsnnincG9S%2BgS2uW9Fknh5rCpnYHuFtA%40mail.gmail.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/CAFRtmODAvy8To4jCAk-n%3DvffzPFKGLiQu%2B19RCgapnLG%2BF%3DBKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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/CAPGFgA1hnJpqDSN5AwhRX9jbvgefi5_GnJrf19DQGxW2QgnHDQ%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA3GN9tH%3Dz13BwwVQo35fzkv63-c4iM3xuuSsmZxJ5f%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA38%2BW2k7W1bpMYsnnincG9S%2BgS2uW9Fknh5rCpnYHuFtA%40mail.gmail.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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODAvy8To4jCAk-n%3DvffzPFKGLiQu%2B19RCgapnLG%2BF%3DBKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1hnJpqDSN5AwhRX9jbvgefi5_GnJrf19DQGxW2QgnHDQ%40mail.gmail.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/48e9aad8-f50d-4991-ae08-01676a87b5fe%40googlegroups.com.