opening the serial port in Python will reset the Arduino
try this
import serial
ser = serial.Serial("COM31", 115200)
def main():
ser.close()
ser.open()
while(True):
print ser.inWaiting()
print ser.read(1)
if __name__ == '__main__':
main()