title: Matching ctrl-M character in Python
body: <p>I am working on an interactive program where I take some actions based on the input. For the application I want to match <code>^M</code> characters in the input stream.</p>
  
  <p>To do this I found the ASCII equivalent of <code>^M</code> which is <code>0xd</code> and converted the input character to ascii using <code>hex(ord(char))</code> and compared the two.</p>
  
  <pre><code>if hex(ord(char)) == 0xd:
      take_action()
  </code></pre>
  
  <p>But this condition never evaluates to true. To see if I am using the correct ascii values I wrote the input I am sending to a file.</p>
  
  <pre><code> 0xd
   0xd
   0xd
   0x65
   0x78
   0x69
   0x74
   0xd
   0x65
   0x78
   0x69
   0x74
   0xd
  </code></pre>
  
  <p>Could anyone tell me how to compare <code>^M</code> character and why the above does not work ?</p>