Something I apreciate when using python with Maya is quotes. Since python lets you use ' or " you can save a few keystrokes and make your code a bit more readable. Here's a little example:
in MEL:
eval("error "too big"")
in Python:
import maya.mel as mel
mel.eval( 'error "too big"' )
Quotes make code readable
In order to post any comments, you must be logged in!
You can program in bothon Python and MEL, though sticking to one language is a good idea. There are some cases where you will want to call Python from MEL or MEL from python - the example above being an example as MEL's error command turns the feedback line red.
The next part is the diferent types of quotes - I find them to be more readable in my text editor than this font. Note that my example used ' (single quote) and " double quote. MEL users are used to ` (left quote) for getting the results of commands.
Finally, the Python equivalent of:
string $myTrans = `getAttr ($each + ".tx")`;
is:
myTrans = maya.cmds.getAttr(each + '.tx')
The next part is the diferent types of quotes - I find them to be more readable in my text editor than this font. Note that my example used ' (single quote) and " double quote. MEL users are used to ` (left quote) for getting the results of commands.
Finally, the Python equivalent of:
string $myTrans = `getAttr ($each + ".tx")`;
is:
myTrans = maya.cmds.getAttr(each + '.tx')
coming from a non-programmer back ground, I actually think I would find this more confusing, since in mel you use the tick marks to delineate running mel statments.
ie: string $myTrans = `getAttr ($each + ".tx")`;
how does the above statement look in python?
I would imagine, exactly the same.
but since in mel you can't do this
eval(`error\"too big\"`);
for me personally, I would prob keep that as " rather than ` to make it easier to read.
or is the idea, that one would only program in python or in mel, and not both?
ie: string $myTrans = `getAttr ($each + ".tx")`;
how does the above statement look in python?
I would imagine, exactly the same.
but since in mel you can't do this
eval(`error\"too big\"`);
for me personally, I would prob keep that as " rather than ` to make it easier to read.
or is the idea, that one would only program in python or in mel, and not both?
Page 1 of 1 pages




