IronPython - 如何导入 Gzip?

发布于 2024-09-19 19:43:15 字数 106 浏览 1 评论 0原文

我正在尝试在 VS 2010 下使用 IronPython。

我需要 Gzip,但没有(我可以找到)文档告诉我如何“引用”或添加模块。

谁能告诉我如何添加 Gzip。

I am trying to use IronPython under VS 2010.

I need Gzip, but there is no (that I can find) documentation to tell me how to "reference" or add a module.

Can anyone tell how to add Gzip please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被翻牌 2024-09-26 19:43:37
import clr
from System.IO.Compression import GZipStream

#or if your implementation is in some external assembly
clr.AddReference("<assembly-with gzip implementation>")
# from Gzip import Impl blah-blah-blah 
import clr
from System.IO.Compression import GZipStream

#or if your implementation is in some external assembly
clr.AddReference("<assembly-with gzip implementation>")
# from Gzip import Impl blah-blah-blah 
等风来 2024-09-26 19:43:30

首先,IronPython 不包含 gzip 模块,因为它不受开箱即用的支持。您可以从 Python 源代码树或 http:// bitbucket.org/jdhardy/ironpythonzlib/src/tip/tests/gzip.py。将此文件放入 IronPython 安装的 Lib 文件夹中。

接下来,您需要实现 IronPython 的 zlib;您可能需要 .NET 4.0 的“clr4”版本。将 IronPython.Zlib.dll 放入 IronPython 安装的 DLLs 文件夹中;如果DLLs文件夹不存在,则创建它。

如果您无法修改 IronPython 安装(对于 VS 2010,我认为您不能),请将 gzip.py 和 IronPython.Zlib.dll 与其余文件放在同一文件夹中,然后添加以下行靠近 gzip.py 顶部,在其他 import 语句之后:

if sys.platform == 'cli':
    import clr
    clr.AddReference('IronPython.Zlib')

无论哪种方式,您现在应该能够从 IronPython 导入 gzip。

First off, IronPython does not include the gzip module because it's not supported out of the box. You can pull a copy from the Python source tree or from http://bitbucket.org/jdhardy/ironpythonzlib/src/tip/tests/gzip.py. Put this file in the Lib folder of your IronPython installation.

Next, you need an implementation of zlib for IronPython; you probably want the 'clr4' version for .NET 4.0. Put IronPython.Zlib.dll in the DLLs folder of your IronPython installation; if the DLLs folder does not exist, just create it.

If you can't modify the IronPython install (and with VS 2010, I don't think you can), put gzip.py and IronPython.Zlib.dll in the same folder as the rest of your files, and add the following lines near the top of gzip.py, after the other import statements:

if sys.platform == 'cli':
    import clr
    clr.AddReference('IronPython.Zlib')

Either way, you should now be able to do import gzip from IronPython.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文