Python> coding rule> PEP8> read_chpoint.py: 20: 1: E302 expected 2 blank lines, found 1

Operating environment


GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

I'm trying PEP8 checking of code written in Python. Reference http://qiita.com/clarinet758/items/312e95ee1513560dfdd1

Run


$ pep8 read_chpoint.py | head
read_chpoint.py:20:1: E302 expected 2 blank lines, found 1
read_chpoint.py:21:1: E101 indentation contains mixed spaces and tabs
read_chpoint.py:21:1: W191 indentation contains tabs
...

The relevant part of the code is the def line of the following wrap_fromfile ().

read_chpoint.py


import numpy as np
import array
import sys

'''
v0.5 Dec. 23, 2016
    - wrap_fromfile() takes [num] arg
v0.4 Dec. 21, 2016
    - read from "auxiliary" file [auxfp]
        + add read_auxiliary_info()
v0.3 Dec. 19, 2016
    - add wrap_fromfile()
    - read [inprodR],[prev_err],[resid_scale]
v0.2 Dec. 19, 2016
    - fix bug > read [local_nRows] for "size_t" type
v0.1 Dec. 18, 2016
    - read_chpoint_file() > read [ind_m],[local_nRows],[niter],[counter]
'''

def wrap_fromfile(rfp, typecode, num):
	res = array.array(typecode)
...

Coping

There was one blank line under the comment, but it seems to be two lines.

read_chpoint.py


import numpy as np
import array
import sys

'''
v0.5 Dec. 23, 2016
    - wrap_fromfile() takes [num] arg
v0.4 Dec. 21, 2016
    - read from "auxiliary" file [auxfp]
        + add read_auxiliary_info()
v0.3 Dec. 19, 2016
    - add wrap_fromfile()
    - read [inprodR],[prev_err],[resid_scale]
v0.2 Dec. 19, 2016
    - fix bug > read [local_nRows] for "size_t" type
v0.1 Dec. 18, 2016
    - read_chpoint_file() > read [ind_m],[local_nRows],[niter],[counter]
'''


def wrap_fromfile(rfp, typecode, num):
	res = array.array(typecode)
	res.fromfile(rfp, num)
...

With the above fix, the related error disappeared.

Run


$ pep8 read_chpoint.py | head
read_chpoint.py:22:1: E101 indentation contains mixed spaces and tabs
read_chpoint.py:22:1: W191 indentation contains tabs
read_chpoint.py:23:1: W191 indentation contains tabs
read_chpoint.py:24:1: W191 indentation contains tabs
read_chpoint.py:26:1: E302 expected 2 blank lines, found 1
read_chpoint.py:27:1: W191 indentation contains tabs
read_chpoint.py:28:1: W191 indentation contains tabs
read_chpoint.py:28:35: E261 at least two spaces before inline comment
read_chpoint.py:28:36: E262 inline comment should start with '# '
read_chpoint.py:29:1: W191 indentation contains tabs

Recommended Posts

Python> coding rule> PEP8> read_chpoint.py: 20: 1: E302 expected 2 blank lines, found 1
R / Python coding rule link summary
Comply with Python coding standard PEP8
Let's summarize the Python coding standard PEP8 (1)
python> coding guide> PEP 0008 --Style Guide for Python Code
Let's summarize the Python coding standard PEP8 (2)
[Python coding standard] PEP 8 vs Google Style