pylint 抛出错误,但代码对我有用
pylint throws an error but the code works for me
if n>2:
for i in range(0,n):
print(check_prime(i), end = " ")
在此代码的最后一行,PyLint 给出了一个 "syntax-error" 但该代码适用于我测试过的内容。
发生这种情况的原因是什么?
您的代码显然是 Python 3 代码(因为您使用了 print 函数,所以可以看出这一点)。
但是,如果你 运行 PyLint 安装在 Python 2 virtualenv 上,你会得到一个错误:
************* Module ...
E: 11, 0: invalid syntax (<string>, line 11) (syntax-error)
要解决这个问题,您需要 Python 3 virtualenv。
python -m venv my_projet
source my_project/bin/activate
pip install pylint
pylint path/to/my_file.py
if n>2:
for i in range(0,n):
print(check_prime(i), end = " ")
在此代码的最后一行,PyLint 给出了一个 "syntax-error" 但该代码适用于我测试过的内容。
发生这种情况的原因是什么?
您的代码显然是 Python 3 代码(因为您使用了 print 函数,所以可以看出这一点)。
但是,如果你 运行 PyLint 安装在 Python 2 virtualenv 上,你会得到一个错误:
************* Module ...
E: 11, 0: invalid syntax (<string>, line 11) (syntax-error)
要解决这个问题,您需要 Python 3 virtualenv。
python -m venv my_projet
source my_project/bin/activate
pip install pylint
pylint path/to/my_file.py