我有一个可以在 Python 2 和 Python 3 上运行的 Python 模块。在某些时候,该模块需要用户输入。它如何做到这一点取决于 Python 主要版本:
- Python 2:使用
raw_input
- Python 3:使用
input
我的 IDE 是 PyCharm,我的项目解释器是 Python 3.8
。PyCharm 检查raw_input
.
除了# noinspection PyUnresolvedReferences
标签,我怎样才能让 PyCharm 不抱怨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))
我在屏幕上看到的内容:
版本
- Python:
3.8.2
- PyCharm:
CE 2019.3.1
我的 PyCharm 已Code compatibility inspection
为 Python 2.7
、3.6
、3.7
和3.8
.