--
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/c34f5e0c-2b7a-42a5-856d-84b38ad5f5c3o%40googlegroups.com.
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. :)
--
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/b9f25e83-e9b3-485f-b8f6-831a43432550o%40googlegroups.com.
class Person(object):
def __init__(self, name, lastName):
self.name = name
self.lastName = lastName
@property
def fullName(self):
return self.name + " " + self.lastName
obj.attr1.attr2.foo()
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBx4ysUspDmV5gYNKOQ4GHBrShzwkD%2BnqqoSHFjHi1ceQ%40mail.gmail.com.
class Foo(object):
def __init__(self, input_):
self.input = input_
@property
def x(self):
trans = cmds.getAttr(self.input + ".tx")
return trans
@x.setter
def x(self, value):
if self.x >= 0:
cmds.setAttr(self.input + ".tx", value)
else:
pass
jnt = cmds.joint()
foo = Foo(jnt)
foo.x
foo.x = 5
foo.x = foo.x + 10
# vs
class Foo(object):
def __init__(self, input_):
self.input = input_
def getX(self):
trans = cmds.getAttr(self.input + ".tx")
return trans
def setX(self, value):
if self.getX() >= 0:
cmds.setAttr(self.input + ".tx", value)
else:
pass
jnt = cmds.joint()
foo = Foo(jnt)
foo.getX()
foo.setX(5)
foo.setX(foo.getX() + 10)foo.x = foo.x + 10 is a much more clear than foo.setX(foo.getX() + 10)So this example isn't a read only attribute case. You can get and set. Aren't cases like that aslo a good use of properties?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/b9f25e83-e9b3-485f-b8f6-831a43432550o%40googlegroups.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 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/b9f25e83-e9b3-485f-b8f6-831a43432550o%40googlegroups.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/CAFRtmOBx4ysUspDmV5gYNKOQ4GHBrShzwkD%2BnqqoSHFjHi1ceQ%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/7f1f0385-417c-4895-936d-0426c2ccd7c7o%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2m7sfTXY%3D88knS6JvFNzEao73f-ZNhuffOdKEcxVfrVw%40mail.gmail.com.