The line print(var) gives me b'mystring'
Question: In Python, this code:

    
    
    import serial
    ser = serial.Serial('COM6', 115200)
    while 1:
        a = ser.readline()
        print(a)
    x = input("don't exit :)")
    

Gives me:

    
    
    b'my serial data'
    

How do I take off this b''?


Answer: Python 3 makes a distinction between bytes and text. If you're sure the serial
data is actually text, you can use `decode`. `decode` needs to know what
character encoding your data is. If it's only going to be sending English text
without anything tricky like "café" or "naïve", ASCII will probably be okay:

    
    
    text = data.decode('ascii')
    

If, however, it is not textual data, then you really _do not_ want to be
removing that `b''` part. You'll want to process it while it's still in its
`bytes` form. How to do that depends on what exactly you want to do with it,
just as if it were a textual string.

