PDA

View Full Version : Python - Switch / Case statement


trancor
09-20-2007, 06:50 PM
Hey, I'm having some trouble getting switch statements to work in python.

If I have -

x=1

switch x:
case '1':
print("Poo")
case '2':
print("Goob")


it gives me this as an error -

# Error: ('invalid syntax', ('<maya console>', 5, 8, 'switch x:\n'))
# File "<maya console>", line 3
# switch x:
# ^
# SyntaxError: invalid syntax #

If the carrot isn't pointing to the x, it was in the error


Now I've tried -
switch x:
switch 'x':
switch "x":
switch (x):
switch ('x'):

And every time maya either doesn't like the : or the digit after the x.

If anyone knows how to get switches in python working, I think you in advance

marcinm
09-20-2007, 11:18 PM
Python doesn't have switch-case statement. Take a look at http://www.python.org/dev/peps/pep-0275/. There are many ways to emulate this type of statement.

CGTalk Moderation
09-20-2007, 11:18 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.