Username
Password
Auto-login
Show my name in the online users list
Not a member?
Please register.
Forgot your password?
(1) October 2008
(6) September 2008
(7) August 2008
(6) July 2008
(9) June 2008
(4) May 2008
(6) April 2008
(6) March 2008
(4) February 2008
(5) January 2008
(8) December 2007
(4) November 2007
Quotes make code readable
Posted: May 04, 2007 - 06:19 PM
Category: Python
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"' )
In order to post any comments, you must be logged in!
  Posted by cmogk  on  07 May, 2007  at  12:07 AM
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')
  Posted by Smann  on  04 May, 2007  at  12:26 AM
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?











 
Page 1 of 1 pages