简体   繁体   English

python 2的Inspect模块中的签名方法

[英]Signature method in Inspect module for python 2

I am trying to run a Python 3 library in Python 2. It uses inspect module and signature method which is not implemented in Python 2 version of the module.我正在尝试在 Python 2 中运行 Python 3 库。它使用在模块的 Python 2 版本中未实现的inspect模块和signature方法。

signature = inspect.signature(initializer)

There is no implementation in __future__ that can help (at least, I haven't found one). __future__中没有可以提供帮助的实现(至少,我还没有找到)。

How can I replace this method?我怎样才能替换这个方法?

Package funcsigs on PyPI is a backport of PEP-362 (which adds signature introspection) to Python 2.6+. PyPI 上的包funcsigsPEP-362 (增加了签名自省)到 Python 2.6+ 的后向移植。 So change the line in question to因此,将有问题的行更改为

import funcsigs
signature = funcsigs.signature(initializer)

inspect2 is backport of the entire Python 3.6 inspect module to Python 2.7. inspect2是整个 Python 3.6 inspect模块到 Python 2.7 的inspect2移植。 Like funcsigs it is also available from PyPI, and inspect2 is more recently maintained.funcsigs一样,它也可以从 PyPI 获得,而inspect2是最近维护的。 (As I'm writing this, inspect2 was last updated in 2019, while funcsigs was last updated in 2016.) (在我写这篇文章时, inspect2上次更新是在 2019 年,而funcsigs上次更新是在 2016 年。)

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

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