Python How to avoid many if statements
<p>I'll try to simplify my problem. I'm writing a test program using py.test and appium. Now:</p>

<p>In the application I have 4 media formats: <strong>Video, Audio, Image and Document.</strong>
I have a control interface with <strong>previous, next, play , stop buttons.</strong>
Each media formats has a unique ID like</p>

<p>video_playbutton, audio_playbutton, document_playbutton,    image_playbutton, video_stopbutton audio_stopbutton ...etc etc.</p>

<p>But the operation I have to do is the same for all of them e.g press on playbutton.</p>

<p>I can address playbutton of each when i give them explicitly like this</p>

<pre><code>find_element_by_id("video_playbutton")
</code></pre>

<p>And when i want to press on other playbuttons I've to repeat above line each time. Like this:</p>

<pre><code>find_element_by_id("video_playbutton")
find_element_by_id("audio_playbutton")
find_element_by_id("image_playbutton")
find_element_by_id("document_playbutton")
</code></pre>

<p>And because I'm calling this function from another script I would have to distinguish first what string I got e.g:</p>

<pre><code>def play(mediatype):
    if mediatype == "video"
          el = find_element_by_id("video_playbutton")
          el.click()
    if mediatype == "audio"
          el = find_element_by_id("audio_playbutton")
          el.click()
    if .....
</code></pre>

<p>What is the best way to solve this situation? I want to avoid hundreds of if-statements because there is also stop, next , previous etc buttons.</p>

<p>I'm rather searching for something like this</p>

<pre><code>def play(mediatype)
    find_element_by_id(mediatype.playbutton)
</code></pre>