Skip to content

Instantly share code, notes, and snippets.

@kxxoling
Last active April 20, 2017 09:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kxxoling/3b0d9bf77b085d103fd6 to your computer and use it in GitHub Desktop.
Save kxxoling/3b0d9bf77b085d103fd6 to your computer and use it in GitHub Desktop.
Python 2-3 兼容库 six

由于 Python 在 2-3 版本的升级过程中的激进演变,导致了应用的兼容困难, 很多第三方库为了同时兼容 Python 2 和 3 不得不使用一些难看的 patch 来解决兼容性问题。 比较常见的做法是自己编写 _compat.py(compatibility 的缩写) 或者直接使用 six 库。

six 支持 Python 2.5+ 版本,你可以引用它,也可以将其直接复制到代码库中。

six 是 2*3 的意思,之所以使用 2*3 而不是 2+3 ,是因为 five 这个名字已经被 Zope Five 所使用。

官方文档:six

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment