;

Pymel Blog Rss Feed

Tuesday, April 3, 2012


Prior to starting any of these lessons be sure to import the PyMEL library. See here for why and how.



Programming languages are often feared by newcomers because of the exacting nature of compilers and interpreters. Leave out a comma and your computer will respond by spitting out obscure error messages leaving you sobbing as a deadline is approaching. The bad news is that Python is no different. A missing colon will make Python cry. But we’re going to kick things off with code that’s guaranteed to pass Python’s watchful eyes: comments!

 

Comments are used when you want to include something in your code that isn't code. This means that you can include "real words". Think of them as digital sticky notes.

 

Comments come in two varieties: Single line comments and multi-line comments. The difference between single line comments and multi-line stem from ancient archeological records found off the coast of Guam. Just kidding. The differences are fairly self-explanatory…but I’ll explain them anyways because I’m your friend.

 

Single lines begin with a "#"

#this is a single line comment
myNode = PyNode("pSphere1")
myOtherNode = PyNode("pSphere2")

See? You can write whatever you want without worrying about Python complaining. You could even write the following:

#Oatmeal gives me gas.
myNode = PyNode("pSphere1")
myOtherNode = PyNode("pSphere2")

See perfectly legal. Maybe a bit TMI and also completely unrelated to any truly useful script whatsoever. But totally legal.

Multi line comments begin with triple quotes and end with triple quotes.

"""
this is a multiline comment.
notice that I am still commenting
please note that I am still in the midst of commenting.
And I won't stop until I am met with another set of triple quotes.
"""
myNode = PyNode("pSphere1")
myOtherNode = PyNode("pSphere2")

For completion, you can also use triple single quotes.

'''
I don\'t know why Bella likes Edward more than Jacob.
I mean, werewolves are so much cooler that vampires.
'''
myNode = PyNode("pSphere1")
myOtherNode = PyNode("pSphere2")

Note that I had to use an escape character for "don't". Because the apostrophe would mess everything up.

 

Bottom line. Comment your code for yourself and for others. Just be sure not to include any comments in your code that you wouldn't want your mother or significant other reading.

 

Speaking of comments, hit me up below if you have anything to say!

My comment system is powered by Disqus. And they require you to put in a name and an email. But I'd love to hear what you think. So if you want to comment anonymously, just put any name and test@test.com for your email.

blog comments powered by Disqus