if sys.platform == 'cli':
    from serialcli import *
else:
    import os
if os.name == 'nt':
    from serialwin32 import *
elif os.name == 'posix':
    from serialposix import *
elif os.name == 'java':
    from serialjava import *
else:
    raise Exception(
        "Sorry: no implementation for your platform ('%s') available" % os.name
        )
Conditional import of modules in Python