Nowadays, when I get the chance, I tend to prefer accessing data either via
a dictionary, or a dictionary-like interface.
data = {}
data["name"] = "Marcus"
For classes, that would then look like..
self._data["name"] = "Marcus"
For example..
widgets["button"].clicked.connect(self.on_clicked)
layout = QtWidgets.QHBoxLayout(panels["footer"])
layout.addWidget(widgets["button"])
I find this extends well to Maya attributes.
import cmdx
node, = cmdx.selection()
node["translateX"] = 5.0
print(node["rx"])
node["newAttribute"] = cmdx.Double(default=6.0)
print(node.path(namespace=True))
That way, I can have this rule.
node.doSomething()
node["storeSomething"]
I mostly avoid @property actually, I haven’t really had a good experience
with those. They’re good on paper.. I like that they prevent accidental
assignment when you e.g. misspell.
node.misspeled = "Bad"# Error
But I don’t like how much extra typing you need (like your example above),
and I most of all don’t like not knowing whether calling your @property
incurs a cost or not.
print(some_class.distance)
Did this return a precomputed distance, or was one computed as I requested
it?
At the end of the day though, most of the time I work in a code base that
isn’t mine and follow whatever convention is already established. Other
times I know the code I write will be edited by others and pick a
convention I expect will be the least surprising and the least distracting.
Your mileage may vary, as they say. :)
On Thu, 6 Aug 2020 at 15:10, Rudi Hammad <[email protected]> wrote:
> Uppss, I pasted the code as a text, sorry, and deleted my coment about it.
> I was saying that I use properties as you do I think. And I posted the
> example above with the cases you described to see if I understood you well.
>
> Cheers
>
> --
> 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/b9f25e83-e9b3-485f-b8f6-831a43432550o%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/b9f25e83-e9b3-485f-b8f6-831a43432550o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CAFRtmOBx4ysUspDmV5gYNKOQ4GHBrShzwkD%2BnqqoSHFjHi1ceQ%40mail.gmail.com.