如何使用Python 2兼容代码不检查raw_input上的错误

问题描述 投票:0回答:1

我有一个可以与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))

我在屏幕上看到的内容:

raw_input unresolved reference


版本

  • Python:3.8.2
  • PyCharm:CE 2019.3.1

[我的PyCharm已为Python Code compatibility inspection2.73.63.7启用了3.8

python pycharm compatibility lint intellij-inspections
1个回答
3
投票

PyCharm不支持​​环境检查,请考虑使用inputsix)中的https://six.readthedocs.io/#module-six.moves

© www.soinside.com 2019 - 2024. All rights reserved.