title: How to read serial port output in Python using pySerial?
body: <p>A device is connected to my PC and I need to write a command via COM Port and get the output. Here is my code</p>
  
  <pre><code>from time import sleep
  import serial
  
  ser = serial.Serial()
  ser.baudrate = 115200
  ser.port = 'COM20'
  
  ser.open()
  ser.write("system\r")
  result = ser.read(100)
  print result
  
  ser.close()
  </code></pre>
  
  <p>This is working perfectly. However, different commands return different strings. so I need to read it <strong>without mentioning</strong> no of bytes in <code>ser.read(100)</code>.</p>
  
  <p>How can I achieve that? Appreciate any help. Thank you</p>