x or y -- if x is false, then y, else x
x and y -- if x is false, then x, else y
not x -- if x is false, then True, else False
"not" has a lower priority than non-Boolean operators, so not a == b is interpreted as not (a == b), and a == not b is a syntax error.
for ($s in $sel)
for s in sel:
for ($i = 0; $i < 4; i++)
for i in range(4):
>>> range(-10, -100, -30) [-10, -40, -70]In the above range case, the range betw. -10 and -100 is being evaluated by an increment of -30 (python.org)
It is possible to write programs that handle selected exceptions. Look at the following example, which asks the user for input until a valid integer has been entered, but allows the user to interrupt the program (using Control-C or whatever the operating system supports); note that a user-generated interruption is signalled by raising the KeyboardInterrupt exception.
>>> while True: ... try: ... x = int(raw_input("Please enter a number: ")) ... break ... except ValueError: ... print "Oops! That was no valid number. Try again..." ...
The try statement works as follows.
The continue statement, also borrowed from C, continues with the next iteration of the loop.
Loop statements may have an else clause; it is executed when the loop terminates through exhaustion of the list (with for) or when the condition becomes false (with while), but not when the loop is terminated by a break statement. This is exemplified by the following loop, which searches for prime numbers:
>>> for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number' ... 2 is a prime number 3 is a prime number 4 equals 2 * 2 5 is a prime number 6 equals 2 * 3 7 is a prime number 8 equals 2 * 4 9 equals 3 * 3
Great post on Python eval vs. mel eval by Ryan Trowbridge
Understanding Python with (Fredrik Lundh)
Simple Decorator Example (Chris Evans)
Dividing using a normal backslash will return a whole integer.
Therefore 4/2 will be 2, but 1/3 = 0!
To get a decimal number, put a point after one or both of the numbers in the division:
1./3 = 0.333333333
8./3. = 2.666666667
In MEL I can execute this:
float $randomize = rand(0,100);
In python I can execute this:
import random as rand
randomize = rand.uniform(0,100)
random.randint(a, b) (but this only returns integers! :( )
random.uniform(a, b) (this returns float vals ^ - ^ )
(module link here)
How to generate the same function using cmds.textField in a window?
Thanks to anyone who can help.
Michiel Duvekot <email@example.com> Dec 04 06:39PM -0800 ^
import maya.cmds as cmds
myList = 
myInt = 0
5.1. Truth Value Testing
All other values are considered true — so objects of many types are always true.
Operations and built-in functions that have a Boolean result always return 0 or False for false and 1 or True for true, unless otherwise stated. (Important exception: the Boolean operations or and and always return one of their operands.)