简体   繁体   English

python IN软件包的替代品是什么?

[英]What is the replacement for python IN package?

I am trying to use a code which was written for python 2 and may run with python 3.6.0, but it does not run with python 3.6.4. 我正在尝试使用为python 2编写的代码,并且可能与python 3.6.0一起运行,但不能与python 3.6.4一起运行。 It imports the IN module, and uses IN.IP_RECVERR. 它导入IN模块,并使用IN.IP_RECVERR。 I tried to google it, but it is a 'bit' hard to find anything about a module called IN (naming fail?). 我试图用谷歌搜索它,但是很难找到有关IN模块的任何信息(命名失败吗?)。 To demonstrate in REPL, that it works in python 2, but not in 3.6.4: 为了在REPL中进行演示,它可以在python 2中使用,但不能在3.6.4中使用:

$ python2
Python 2.7.14 (default, Jan  5 2018, 10:41:29) 
[GCC 7.2.1 20171224] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import IN
>>> IN.IP_RECVERR
11
>>> 
$ python3
Python 3.6.4 (default, Jan  5 2018, 02:35:40) 
[GCC 7.2.1 20171224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import IN
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'IN'
>>> 

What is the replacement for this IN module in newer versions of python 3? 在较新版本的python 3中,此IN模块的替代品是什么?

This is presumably the private plat-linux/IN.py module, which was never intended to be used. 大概是私有的plat-linux/IN.py模块,从来没有使用过。 There have been plans to remove these plat-* files for a few zillion years, but it looks like it finally happened in issue 28027 for 3.6. 计划删除这些plat-*文件已有数百万年的历史,但看起来它终于在3.6 版的28027版本中发生了。 As mentioned in What's New in Python 3.6 : Python 3.6的新增功能中所述

The undocumented IN , CDROM , DLFCN , TYPES , CDIO , and STROPTS modules have been removed. 未记录的INCDROMDLFCNTYPESCDIOSTROPTS模块已被删除。 They had been available in the platform specific Lib/plat-*/ directories, but were chronically out of date, inconsistently available across platforms, and unmaintained. 它们在特定于平台的Lib/plat-*/目录中可用,但长期过时,在各个平台上不一致,并且没有维护。 The script that created these modules is still available in the source distribution at Tools/scripts/h2py.py . 创建这些模块的脚本仍然可以在Tools/scripts/h2py.py的源代码发行版中Tools/scripts/h2py.py

Most of the useful constants that are at least somewhat portable (as in you can expect them to be available and work the same on your old laptop's linux and your brand-new Galaxy's linux, if not on OS X or Solaris) have long been made available through other places in the stdlib. 长期以来,大多数至少在某种程度上可移植的有用常量(如您所期望的那样,它们是可用的,并且在旧笔记本电脑的Linux和全新的Galaxy的Linux(如果不在OS X或Solaris上)上也可以正常工作)可通过stdlib中的其他位置获得。

I think this specific one you're looking for is an example of not completely useless, but not portable enough to put anywhere safe, because linux documents the existence of IP_RECVERR , but not its value. 我认为您正在寻找的特定实例不是完全没有用的示例,但又不够便携以至于不能放到任何地方,因为linux记录了IP_RECVERR的存在,但没有它的价值。 So, you really need the version from your own system's ip headers. 因此,您确实需要您自己系统的ip标头中的版本。

The way to do this safely, if you actually need the IN module, is to run Tools/scripts/h2py.py with the Python version you're using, on the specific platform you need. 如果确实需要IN模块,则安全地执行此操作的方法是在所需的特定平台上使用所使用的Python版本运行Tools/scripts/h2py.py That will generate an IN.py from the appropriate headers on your system (or on your cross-compilation target), which you can then use on that system. 这将从系统(或交叉编译目标)上的适当头生成IN.py ,然后可以在该系统上使用。 If you want to distribute your code, you'd probably need to put a step to do that into the setup.py , so it'll be run at install time (and at wheel-building time for people who install pre-built wheels, but you may need to be careful to make sure the targets are specific enough). 如果您想分发代码,则可能需要在setup.py采取步骤,以便在安装时运行(对于安装预构建车轮的人,则在车轮制造时运行)。 ,但您可能需要小心以确保目标足够具体)。

If you don't need to be particularly portable, you just need to access the one value in a few scripts that you're only deploying on your laptop or your company's set of identical containers or the like, you may be better off hardcoding the values (with a nice scare comment explaining the details). 如果您不需要特别便携,则只需要访问几个脚本(仅部署在便携式计算机或公司的一组相同容器等中)中的一个值,最好对它们进行硬编码值(带有详细说明的惊恐评论)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM