def enumerate_serial_ports():
 path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
 try:
  key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
 except WindowsError:
  raise StopIteration
 for i in itertools.count():
  try:
   val = winreg.EnumValue(key, i)
   (yield str(val[1]))
  except EnvironmentError:
   break

def enumerate_serial_ports ( ) : path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM' try : key = winreg . OpenKey ( winreg . HKEY_LOCAL_MACHINE , path ) except WindowsError : raise StopIteration for i in itertools . count ( ) : try : val = winreg . EnumValue ( key , i ) ( yield str ( val [ 1 ] ) ) except EnvironmentError : break
uses the win32 registry to return an iterator of serial ports existing on this computer .