Tag: python

Python @property

While learning thru advanced tutorials, it’s time to consolidate some basic concepts in Python. The explanation about property at https://www.programiz.com/python-programming/property is very clear. I’m writing an example below to remind myself of the private variable _cm being a convention only. Name like temp_cm works too.

Also cm is no longer a normal instance variable when property decorator is used. The design of adding @property allows backward compatible to keep codes unchanged!

class Unit:
    def __init__(self, cm=0):
        self.cm = cm

    def toInch(self):
        return self.cm * 0.3937

    # @property
    # def cm(self):
    #     return self.temp_cm
    #
    # @cm.setter
    # def cm(self, v):
    #     self.temp_cm = v

unit = Unit(cm=100)
print(unit.__dict__)

# {'cm': 100}        Without getter setter. The old way.
# {'temp_cm': 100}   With getter setter. The code still runs. It's backward compatible !

Time to Un-learn

Regaining my time, there are long-awaited things I’m going to learn.

Having built several applications with python, I still don’t think I know python well. At the moment I would recommend the course Python for Maya: Beginner to Advanced Rigging Automation by Nick Hughes to beginners. I’ve just skimmed through about 40% of the course. The demo was done in Maya and explanation is thorough. The early parts are mostly basic but I start to find sth useful for better coding. In the past I would write

def f(nameList):
    for name in nameList:
        mc.polyCube(n=name)

f(['a','b'])

Now I could skip the for loop with map function

def f(name):
    mc.polyCube(n=name)
    
list(map(f,['a','b']))

Another one I’d like to share is The Gnomon Workshop – Automating Animation & Game-Ready Rigs by Nick Miller. It’s more advanced and I did fasten my seat belt to learn from him. He is undoubtedly an expert and made things “easy”. The videos are done so next is to study his codes and thought in OOP way.


Cloudy Saturday

Oh yes I’m here. It’s been a while not having posts here. Life is like repeating itself when writing various tools for 3ds max. Maxscript has “interesting” design which take me longer to make usable things.

I picked up simple TCL and python for building tools in nuke & nuke studio. TCL is a terrible language to me at the beginning. I wish I was a hard-core programmers then I might get it to work quicker. Inserting and reading custom metadata in DPX is another “old” problem I’m about to tackle finally in the last few weeks.

And it’s embarrassing to tell that I’m learning to use git for my codes recently, before they got messed up too much. http://www.gitlab.com¬†seems like a popular choice.

Sound boring. Hopefully got some visual stuff to share later.