title: How to compare a string with a python enum?
body: <p>I just discovered the existence of an <a href="https://docs.python.org/3/library/enum.html" rel="noreferrer">Enum</a> base class in python and I'm trying to imagine how it could be useful to me.</p>
  
  <p>Let's say I define a traffic light status:</p>
  
  <pre><code>from enum import Enum, auto
  
  class Signal(Enum):
      red = auto()
      green = auto()
      orange = auto()
  </code></pre>
  
  <p>Let's say I receive information from some subsystem in my program, in the form of a string representing a colour name, for instance <code>brain_detected_colour = "red"</code>.</p>
  
  <p><strong>How do I compare this string to my traffic light signals?</strong></p>
  
  <p>Obviously, <code>brain_detected_colour is Signal.red</code> is <code>False</code>, because <code>Signal.red</code> is not a string.</p>
  
  <p><code>Signal(brain_detected_colour) is Signal.red</code> fails with <code>ValueError: 'red' is not a valid Signal</code>.</p>