0

我有一个可以在 Python 2 和 Python 3 上运行的 Python 模块。在某些时候,该模块需要用户输入。它如何做到这一点取决于 Python 主要版本:

  • Python 2:使用raw_input
  • Python 3:使用input

我的 IDE 是 PyCharm,我的项目解释器是 Python 3.8。PyCharm 检查raw_input.

除了# noinspection PyUnresolvedReferences标签,我怎样才能让 PyC​​harm 不抱怨raw_input?我可以启用一些设置吗?


示例代码

#!/usr/bin/python


import sys


if sys.version_info[0] > 2:
    some_input = input("Please give input: ")
else:
    some_input = raw_input("Please give input: ")

print("input: {}".format(some_input))

我在屏幕上看到的内容:

raw_input 未解析的参考


版本

  • Python:3.8.2
  • PyCharm:CE 2019.3.1

我的 PyCharm 已Code compatibility inspection为 Python 2.73.63.73.8.

4

1 回答 1

3

PyCharm 不支持环境检查,请考虑使用inputfrom six( https://six.readthedocs.io/#module-six.moves )。

于 2020-03-22T22:02:54.497 回答