Python newbie here.

I am writing a simple script in Python, using the 2.7.3 distribution from Cygwin. I want to access/modify Windows Registry from this script. I found out that the _winreg module is not available on cygwin python but that an alternative cygwinreg exists.

The users of this script do not have cygwin python, they have the windows python install. Is it possible to write a python script that would work on both?

有帮助吗?

解决方案

Sure, just do this:

try:
    import _winreg
except ImportError:
    import cygwinreg as _winreg

Or maybe

import sys

if sys.platform == 'win32':
     import _winreg
elif sys.platform == 'cygwin':
     import cygwinreg as _winreg
else:
     # non-windows support
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top