Test if byte is empty in python
<p>I'd like to test the content of a variable containing a byte in a way like this: </p>

<pre><code>line = []
while True:
    for c in self.ser.read(): # read() from pySerial
        line.append(c)
        if c == binascii.unhexlify('0A').decode('utf8'):
            print("Line: " + line)
            line = []
            break
</code></pre>

<p>But this does not work...
I'd like also to test, if a byte is empty:
In this case</p>

<pre><code>print(self.ser.read())
</code></pre>

<p>prints: b'' (with two single quotes)</p>

<p>I do not until now succeed to test this</p>

<pre><code>if self.ser.read() == b''
</code></pre>

<p>or what ever always shows a syntax error...</p>

<p>I know, very basic, but I don't get it...</p>

<p>If you want to verify the contents of your variable or string which you want to read from pySerial, use the <code>repr()</code> function, something like:</p>

<pre><code>import serial
import repr as reprlib
from binascii import unhexlify
self.ser = serial.Serial(self.port_name, self.baudrate, self.bytesize, self.parity, self.stopbits, self.timeout, self.xonxoff, self.rtscts)
line = []
while 1:
    for c in self.ser.read(): # read() from pySerial
        line.append(c)
        if if c == b'\x0A':
            print("Line: " + line)
            print repr(unhexlify(''.join('0A'.split())).decode('utf8'))
            line = []
            break
</code></pre>

python byte