title: How do you read single chars from stdin in Python
body: <p>There are a lot of great answers on how to read from <code>stdin</code> in python, but I just can't find anything about reading single characters instead of whole lines. Let me explain: </p>
  
  <p>I need to read information send by an arduino on a serial port, which is forwarded to stdin. This information is processed and stored in a text file. I wrote the programm on the arduino, so I could change how the information is send. The plan was to send the information with an start- (<code>&lt;</code>) and an endcharacter (<code>&gt;</code>), so it would look like this: <code>&lt;height:2342&gt;</code></p>
  
  <p>There will also be a lot of irrelevant data being written, thats why I decided to use the above form, so the python script can detect the relevant information and capture it. </p>
  
  <p>My python script would check every char individually for the start-character <code>&lt;</code>, ideally as it is entered, and then capture the information until <code>&gt;</code> is received. I tried getting the input using <code>inputchar = sys.stdin.read(1)</code>. But the problem here is that this reads from <code>stdin</code> forever, until a newline (<code>\n</code>) is captured, and then returns the first character entered. </p>
  
  <p>I want this function to return the entered character as soon as it got send to <code>stdin</code>, and not wait for a newline. How do I achive this? </p>
  
  <p><em>Platform: Raspberry Pi Zero W, Raspbian Jessy, Python 2.7</em></p>
  
  <hr>
  
  <p><em>I know I could use</em> <code>inputline = sys.stdin.readline()</code> <em>and change the Arduino programm to send a newline after the information. Then analyze the whole line (which could be very long) and extract the information. But I don't feel this would be a clean way of doing this.</em> </p>
  
  <hr>
  
  <p><strong>Update on Serial Port:</strong> Sadly I can't access the serial port directly from python because there is a second python script which has to write to the serial port. Since only one can access the port, the solution is to redirect the serial port to <code>stdin</code> and <code>stdout</code>. See my question <a href="https://unix.stackexchange.com/questions/441176/access-one-serial-port-with-two-python-scripts">Access one Serial Port with two Python Scripts</a></p>