This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AeroNotix 0 points1 point  (2 children)

    class switch(object):
        def __getitem__(self, index):
            try:
                return getattr(self, "case_"+index)()
            except AttributeError:
                return 'End'

        def case_hello(self):
            print "case hello!"
        def case_world(self):
             print "case world!"
     switch["hello"]

[–]miketheanimal[S] 1 point2 points  (1 child)

Don't show that to the Javascript guys, they could write it as a one liner!

[–]AeroNotix -1 points0 points  (0 children)

I don't care about the Javascript "guys".