Python switch statement

Python doesn’t have a switch statement such as other programming languages but you can do the same thing with a dictionary:

import platform

def set_windows() :
   return
def set_linux() :
   return
def set_sunos() :
   return

platform_settings = {
           'Windows' : set_windows, 
           'Linux'   : set_linux, 
           'SunOS'   : set_sunos,
}

platform_settings[platform.system()]()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s