On Wed, May 17, 2017, 9:39 PM Rudi Hammad <[email protected]> wrote:
> Hi, another question about programing style. > Many times I create a variable in a method (not the __init__) that I use > in another method. And to do this I have to make that variable an attribute > of object with self.myVariable > My question is if I it is okey to do this: > > def foo(self): > myVar = "something" > cmds.joint(n=myVar) > ....more code here that uses myVar > .... > .... > self.myVar = myVar > > > Is this a normal thing to do, or should I right directly from the > beginning self.myVar = "something" > The main reason is to keep things a little bit shorter, and not see self. > repited all over the code. > As long as you don't trigger any methods in your elided "more code" which will rely on that attribute to exist, then it would be fine. It is normally safer to set the fields to a default value in your__init__. Especially public attributes. > > -- > 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/4c554812-164b-43dc-a62b-ce3e3bf0b209%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/4c554812-164b-43dc-a62b-ce3e3bf0b209%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0%2BAqQ-Dh3h-CpnPkGAtoFJKAaRWKKmEs-%3DJUNXciSyYQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
