【问题标题】:Cygwin Python Script using cygwinreg that can run on the Windows Python使用 cygwinreg 的 Cygwin Python 脚本,可以在 Windows Python 上运行
【发布时间】:2013-02-14 22:13:00
【问题描述】:

这里是 Python 新手。

我正在用 Python 编写一个简单的脚本,使用 Cygwin 的 2.7.3 发行版。我想从此脚本访问/修改 Windows 注册表。我发现 _winreg 模块在 cygwin python 上不可用,但存在替代 cygwinreg

这个脚本的用户没有 cygwin python,他们有 windows python 安装。是否可以编写一个适用于两者的python脚本?

【问题讨论】:

    标签: python cygwin winreg


    【解决方案1】:

    当然,只要这样做:

    try:
        import _winreg
    except ImportError:
        import cygwinreg as _winreg
    

    或许

    import sys
    
    if sys.platform == 'win32':
         import _winreg
    elif sys.platform == 'cygwin':
         import cygwinreg as _winreg
    else:
         # non-windows support
    

    【讨论】:

      猜你喜欢
      • 2019-09-11
      • 2016-03-10
      • 1970-01-01
      • 2013-03-22
      • 2013-06-22
      • 2010-10-29
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      相关资源
      最近更新 更多