python-dev Summary for 2004-02-01 through 2004-02-29

Josiah Carlson jcarlson at nospam.uci.edu
Thu Mar 18 16:32:53 EST 2004


> I do it.  I have some code that talks to pySerial.  On Windows
> it can throw an exception type that is part of win32all and
> hence not present on other platforms.
> 
>    modeignoreerrortypes=[ commport.CommTimeout,
>                           common.CommsDeviceNeedsAttention ]
>    try:
>        import pywintypes
>        modeignoreerrortypes.append(pywintypes.error)
>    except:
>        pass
> 
>    # has to be tuple or it doesn't work
>    modeignoreerrortypes=tuple(modeignoreerrortypes)
> 
> Later on in my code I detect a broken driver (most of the
> time I am actually talking to USB to serial connections).
> When that happens it starts giving dud exceptions which
> I add to the above list (I only want to do it for the
> broken driver, not all cases).


There is nothing wrong with adding tuples.  I would expect that normally 
the number of exceptions is somewhat small, so the overhead of tuple 
addition is not that bad...

    modeignoreerrortypes=(commport.CommTimeout,
                          common.CommsDeviceNeedsAttention)
    try:
        import pywintypes
        modeignoreerrortypes += (pywintypes.error,)
    except:
        pass


  - Josiah



More information about the Python-list mailing list