python - Flake8 报告 E999 SyntaxError atom Flake 8

标签 python flake8

我无法解决 flake8 SyntaxError,尽管代码执行得很好。
enter image description here
没有注释的代码

import math


def answer(str_n):
    sume = ((str_n * (str_n + 1)) / 2) * math.sqrt(2)
    sume = int(sume)
    return sume


def answer1(str_n):
    sume = 0
    for i in range(str_n + 1):
        sume += math.floor(i * math.sqrt(2))
        # print i,math.floor(i*math.sqrt(2))
    return sume


print "Test answer:", answer(77)
print "Actual answer:", answer1(77)

最佳答案

Flake8 启动器将 Python3 硬编码为主要 Python。

怎么修:

1) 使用 pip 安装 flake8 包
$ pip install flake8
pip 会告诉您 flake8 脚本尚未添加到路径并打印路径(在我的情况下为 /Library/Frameworks/Python.framework/Versions/2.7/bin/)

2) 调整您的 IDE (Atom/PyCharm/etc) 以将此脚本与您的默认 Python 2.7 一起使用(我的示例来自 PyCharm @ MacOS):

PyCharm -> Preferences -> External tools -> "flake8 - current file"
Program: /usr/local/bin/python 
Arguments: /Library/Frameworks/Python.framework/Versions/2.7/bin/flake8 --ignore=E501,E124,E127,E128 $FilePath$
Working directory: $FileDir$

[x] open console for tool output 
Output filters: $FILE_PATH$\:$LINE$\:.*


它将正常工作而不报告 E999.ha

PyCharm preferences screenshot

关于python - Flake8 报告 E999 SyntaxError atom Flake 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46745598/

相关文章:

python-2.7 - DistributionNotFound 在 Mac OS X 上运行 flake8

重新定义函数的 Pythonic 方式? (Flake8 F811 错误)

python - flake8 不报告太长的行

python - 使用工作流在 github 中对 databricks python 代码进行 flake8 linting

python - 在所有列聚合后重命名所有列

python - 使用正则表达式提取不同格式的日期并对它们进行排序 - pandas

python - Python 中的就地快速排序

python - 如何修复 flake 8 错误 "E712 comparison to False should be ' 如果 cond 为 False :' or ' 如果不是 cond :'"在 pandas dataframe

python - 如何使用 numpy.genfromtxt 将下三角矩阵读入 numpy 数组?

python - 完整性错误 *_id 不能为空