Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python Switch Statement

Name: Anonymous 2010-11-20 17:24

I'm just learning python and realize that there's no switch-case in python. This really kills my mood to learning python. What do you think of this python programmers?

Name: Anonymous 2010-11-20 17:30

Learn to elif, faggot!

Name: Anonymous 2010-11-20 17:35

You're often advised to use a dictionary with functions instead, though that tends to break the natural flow of the code IMO.

Name: Anonymous 2010-11-20 17:40

That python doesn’t have a switch statement is a huge black mark on the language and, frankly is an absolutely stupid decision. Switch statements are more powerful than any ugly python hack.

“But then again using case/switch would violate python’s principle of using as few idioms as possible, so as to not confuse the average programmer.”

If switch statements are confusing, then that “programmer” should find a new field.

Name: Anonymous 2010-11-20 17:46

{'match': function}[case](parameters)

Name: Anonymous 2010-11-20 17:48

>>2
Yeah, sure
Everybody loves HUGE if else blocks. So easy to read!
And no dictionary can't really replace switch statement awesomeness (default, break, etc)

Name: Anonymous 2010-11-20 18:02

>>4
fold was removed for the same reason. Go figure.

Name: Anonymous 2010-11-20 18:13

Chill out. One day Guido will figure out that the community is bored and will design a new language called Python 4. After a few years, a switch statement will be added as a feature to Python 3, which will be quite old by that time.

Name: Anonymous 2010-11-20 18:19

>>4
“But then again using case/switch would violate python’s principle of using as few idioms as possible, so as to not confuse the average programmer.”
... Really? That's the reason? Do I have bitch tits?

Name: Anonymous 2010-11-20 18:27

Lack of a switch-case construct is indeed one of Python's weaknesses. No, a combination of dictionaries and functions is not equivalent. Fall through is a feature. When I desire fall through like behavior in Python, I usually use closures with my elif blocks.

Name: Anonymous 2010-11-20 18:31

When I desire fall through like behavior in Python, I usually use closures with my elif blocks.
What the fuck is wrong with you.

Name: Anonymous 2010-11-20 18:34

If, hypothetically, Python was to gain a switch statement, there's no way in hell that it would have fall-trough.

Name: Anonymous 2010-11-20 18:39

>>12
That would make it equivalent to a series of tubif statements.

Name: Anonymous 2010-11-20 18:49

switch anus:
    case 'a':
        while something:
            if something_else:
                something = false
            elif:
                try:
                    blah()
                except NullPointerException:
                    # do something
    case 'b':
        #...
    default:
        #...


Then, add one level of indentation if you put that in an infinite loop.
Python doesn't have a switch statement because it would be ugly as hell.

Name: Anonymous 2010-11-20 18:51

Fallthroughs are bad, you are a shitty coder if you need them

Name: Anonymous 2010-11-20 19:06

>>15
ONE WORD DUFF'S DEVICE. THREAD OVER.

Name: Anonymous 2010-11-20 19:11

>>15
You don't need foreach blocks, but they are useful. It's the same deal.

Name: Anonymous 2010-11-20 20:04

>>17
You don't need high-level languages, but they are useful. It's the same deal.

Name: Anonymous 2010-11-20 21:49

{
    1: lambda: dicks(),
    2: lambda: balls(2),
    3: lambda: hax('anus'),
}.get(switchval, lambda: None)()

Name: Anonymous 2010-11-20 22:29

Name: Anonymous 2010-11-20 22:31

>>19
VALID PERL CODE

Name: Anonymous 2010-11-20 22:54

>>20
I have bitch tits by a female :/

Name: Anonymous 2010-11-21 7:45

also, no op= (i.e., +=, -=, *=, /=, etc.). WHBT

Name: Anonymous 2010-11-21 8:55

>>23
The D Programming Language features both C-like switch statement and op= operators.

Name: Anonymous 2010-11-21 11:08

>>24
So it's just as bloated and stupid as Sepples, except more obscure?

Name: Anonymous 2010-11-22 10:13

Just learn some new stuff and realize you can't put def below it

wow()

def wow():
    print("wow")

It will cause error
Is python really a good language or people just trolling saying it's good?

Name: Anonymous 2010-11-22 10:16

>>26
Just learn some new stuff and realize you can't put def below it
&
people just trolling
:/

Name: Anonymous 2010-11-22 14:05

This is why I don't like languages without macros.

Name: Anonymous 2010-11-22 14:42

>>28
Such as LISP?

Name: Anonymous 2010-11-22 18:13

>>29
This is why I don't like imperative languages without macros.

Name: Anonymous 2010-11-22 21:37

>>30
If Python is an imperative language for you you're using it wrong.

Name: Anonymous 2010-11-22 22:09

>>30
If Python is a programming language for you you're using it wrong.

Name: Anonymous 2010-11-23 2:09

>>26
BEST PRACTICES

def main():
    wow()
def wow():
    print("wow")

if __name__ == '__main__':
    main()

Name: Anonymous 2010-11-23 2:11

>>33

if __name__ == '__main__':
    main()

def main():
    wow()
def wow():
    print("wow")

Name: Anonymous 2010-11-23 6:30

>>33,34
if __name__ == '__main__':
EXPERT FIOC PROGRAMMERThis is why I use Perl

Name: __Anonymous__ 2010-11-23 7:03

>>33-35
U MENA if __name__ == """__main__""":

Name: Anonymous 2010-11-23 11:22

>>33-36
[globals.get(f)() for f in [__name__.strip("""______""")] if hasattr(globals.get(f), """__call__""")]

Don't change these.
Name: Email:
Entire Thread Thread List