Why result of pyserial readlines, when no new data, is not empty list?

355 views Asked by At

I met some problem with pyserial (v3.4) readlines function.

when I run some test codes in IDLE of python 3.5

>>> import serial
>>> ser = serial.Serial('com4', timeout=1)
>>> a = ser.readlines()
>>> a
[]

but when I use the compare "is []", it give me a False

>>> a is []
False

and when I use the compare "== []", it give me a True

>>> a == []
True

I don't understand why that can happen. Is there any way to fix this, or not?

If you could, please help me with this problem.

Thank you very much.


Thank for Jim Fasarakis Hilliard, I have known how to edit the code and make it beautiful in PIP8. I edit and add new code for someone who meet the same problem with me

>>> import serial
>>> ser = serial.Serial('com4', timeout=1)
>>> a = ser.readlines()
>>> if not a:
        DO SOMETHING WHAT YOU WANT
0

There are 0 answers