import serial
import serial.tools.list_ports
port_list = list(serial.tools.list_ports.comports())
port_list_name = []
if len(port_list) <= 0:
print "The Serial port can't find!"
else:
for each_port in port_list:
port_list_name.append(each_port[0])
if __name__ == '__main__':
print port_list_name
运行结果:
[u'COM3', u'COM1', u'COM2', u'COM4']