def myFunc():
"""The description"""
listA = []
listB = []
'''
some code in the middle
bla bla
'''
for i in range(10):
listA.append(i)
'''
more code in the middle
bla bla
'''
for j in range(5):
listB.append(j)def myFunc():
'''
some code in the middle
bla bla
'''
listA = []
for i in range(10):
listA.append(i)
'''
more code in the middle
bla bla
'''
listB = []
for j in range(5):
listB.append(j)--
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/477cb809-6a81-4e21-8168-b8f9c95fda81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I also prefer the second one. Declaring all of your variables at the top of the function body is a very C language thing to do.
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/477cb809-6a81-4e21-8168-b8f9c95fda81%40googlegroups.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/CAPaTLMR1f6JrVrAwr4nOm8x9W5tX%2B3B4SK6R8930wJ%3DxggwS%3DA%40mail.gmail.com.
def foo(self):
myVar = "something"
cmds.joint(n=myVar)
....more code here that uses myVar
....
....
self.myVar = myVar
--
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/4c554812-164b-43dc-a62b-ce3e3bf0b209%40googlegroups.com.
On Wed, May 17, 2017, 9:39 PM Rudi Hammad <rudih...@gmail.com> 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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4c554812-164b-43dc-a62b-ce3e3bf0b209%40googlegroups.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/CAPGFgA0%2BAqQ-Dh3h-CpnPkGAtoFJKAaRWKKmEs-%3DJUNXciSyYQ%40mail.gmail.com.