I am working up to getting Python to read from a microcontroller which sends a short status string every second over COM port.
As the μC (better not say which) has a fairly dodgy serial over USB implementation, I need to regularly check if the COM port exists.
I can use
os.system('python -m serial.tools.list_ports')
s = serial.tools.list_ports
If you're only importing
serial, you can't access
serial.tools directly because
tools is another module (actually, a sub-package) within the
serial package. The
serial package doesn't import it for you. Some packages automatically import some or all of the modules and subpackages they contain, but that behavior needs to be specifically coded by the package developers, it's not done by Python unless you import the inner module yourself.
Try explicitly importing the module you want to use:
import serial.tools.list_ports serial.tools.list_ports.main()
main function implements the behavior you see when you run
python -m serial.tools.list_ports. I found its name by looking in the PySerial subversion repository on Sourceforge.