【问题标题】:How to not inspect error on raw_input with Python 2 compatible code如何不使用 Python 2 兼容代码检查 raw_input 上的错误
【发布时间】:2020-03-22 05:33:44
【问题描述】:

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

我在屏幕上看到的内容:


版本

  • 蟒蛇:3.8.2
  • PyCharm:CE 2019.3.1

我的 PyCharm 为 Python 2.73.63.73.8 启用了 Code compatibility inspection

【问题讨论】:

    标签: python pycharm compatibility lint intellij-inspections


    【解决方案1】:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    • 2011-04-06
    相关资源
    最近更新 更多