hello there guys. im quite confused regarding the use of pyserial classes. ive been reading up on the pyserial documentation. i followed an example and used the code below

import serial
ser = serial.Serial (0 , baudrate = 57600 , timeout = 1) #open serial port (1) - 1
line = ser.readline()
ser.close()

i then checked the pyserial api documentation and found that readline is of the class FileLike http://pyserial.sourceforge.net/pyserial_api.html#serial.FileLike.readline
how is this then possible that one can use the objects(?) from a different class?

Very simple.

You can inherit one class into another if you need its functionality.
That is why we got import in python, #include<> in C,C++ , ...etc.

Anytime you import.... You build your class with that module's class methods but they are not native to your class. That is without the native imported class.... things will break down.

Hope you got it. :)

thanks for the reply. im still quite confused. so you mean even if FileList.readline is not under class serial.serial, as long as it is included in the serial package i can use it?

yep...

because pyserial has included it.
example.,,,,

import serial
ser = serial.Serial (0 , baudrate = 57600 , timeout = 1) #open serial port (1) - 1
line = ser.readline() ## will get the implementation of FileList method readline() if you dont have a local readline() method define

ser.close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.