LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Python --- Switch-case Statement

    Employee
    Posted 08-11-2015 11:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jpstory

    Hi All

    Is Switch-case statement available in the Python node? the reserved word Switch did not turn blue when I type it, Could someone please demonstrate how to code a switch-case statement in the Python node.

    If it's not available in LAE, is there other alternative available to use in Python node, thanks!


  • 2.  RE: Python --- Switch-case Statement

    Employee
    Posted 08-11-2015 11:53

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ddonovan

    Hi... The built-in direct equivalent in Python is to use if / elif / else statements to accomplish the same behavior as a switch / case statement in other languages.

    so, in Python

    if test == a:
          doSomething()
    elif test == b:
          doSomethingElse()
    elif test == c:
          doAnotherThing()
    else:
          doDefaultActon()
    is the equivalent of

    switch(test){
       case a:
           doSomething();
           break;
        case b:
            doSomethingElse();
            break;
        case c:
            doAnotherThing();
            break;
        default:
            doDefaultAction();
    }
    in javascript, for example.

    There are other, more advanced ways of accomplishing this as well. Some examples here: http://stackoverflow.com/questions/6...ment-in-python


  • 3.  RE: Python --- Switch-case Statement

    Employee
    Posted 08-11-2015 12:02

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    All Python functions are available to you thru the node. You just need to keep in mind that it is Python 2.7, not 3.x


  • 4.  RE: Python --- Switch-case Statement

    Employee
    Posted 08-12-2015 10:36

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jpstory

    Very helpful, worked out perfectly, thank you both !!!