介绍

pywin32现在支持Python 3.x. 请注意,Python源代码以Python 2.x语法维护,并使用2to3工具自动转换为Python 3.x语法。 请不要使用Python 3.x语法提交补丁等。

Important: 这py3k的支持是实验性的,事情可能会改变。 特别是,我们偶尔会接受'疯狂'的参数,比如只有unicode字符串对象才有意义时才接受字节等。我们保留清理可能出现的后向不兼容方式的任何此类问题的权利。

到处都是Unicode

In general, pywin32 on Python 2.x will accept both str and unicode objects and convert as appropriate. However, in py3k, bytes objects will generally not be accepted when a 'string' is required - the intent is to restrict usage of bytes objects in py3k to where bytes truly are meant.

Most pywin32 modules for py3k are built with UNICODE defined, and thus will call the Unicode versions of the Windows API.

Specific module notes

isapi

isapi包支持py3k,但请注意,目前只有redirector.py示例已转换为在两种环境中工作 - 特别是,细微的urllib更改可能需要注意 - 请参阅重定向器示例以了解详细信息。

请注意,ISAPI本身是一个基于窄字符的API。 因此,诸如GetServerVariable()等函数都返回字节对象 - 由应用程序来解释这些字节。 pywin32检测以UNICODE_开头的服务器变量,并在这种情况下返回unicode对象 - 请参阅IIS文档以获取更多详细信息。

如果您将一个unicode对象传递给ISAPI函数,它将使用默认编码自动编码,而不是pywin32其余部分使用的“mbcs”编码。 通常这应该避免,因为IIS不定义编码。

datetime objects

Python 3.x builds use a subclass of datetime.datetime objects as the "native" datetime object; a subclass is used to provive a backwards compatible PyDateTime.Format method, but otherwise the datetime object is identical to the base class. All time objects returned by pywin32 will have a UTC timezone (via the win32timezone.TimeZoneInfo.utc() method), and times with any timezone will be accepted when passed to pywin32 - but "time zone naive" objects are *not* supported.

Note that it is possible we will support "time zone naive" objects in the future, as supporting such objects in the future will be fully backwards compatible. However, it is not yet clear that supporting such objects is helpful due to the ambiguities that may arise, and attempting to remove such support in the future would cause more problems than enabling it.

The win32timezone.now and win32timezone.utcnow methods may be useful when working with datetime objects.