IronPython - How do I import Gzip?

我们两清 提交于 2019-12-13 00:23:13

问题


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.


回答1:


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.




回答2:


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 


来源:https://stackoverflow.com/questions/3734593/ironpython-how-do-i-import-gzip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!