4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python / PEP8 > E128 continuation line under-indented for visual indent を解消しようとしてみた

Last updated at Posted at 2017-02-06

TensorFlow

動作環境
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

前置き

original code

実装途中のコード。TensorFlowで100ノード(input)、100ノード(output)の学習予定。

learn_in100out100.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import tensorflow as tf
import tensorflow.contrib.slim as slim
import numpy as np

'''
v0.1 Feb. 06, 2017
    - read [test_in.csv],[test_out.csv]
'''

'''
codingrule:PEP8
'''

filename_inp = tf.train.string_input_producer(["test_in.csv"])
filename_out = tf.train.string_input_producer(["test_out.csv"])
NUM_INP_NODE = 100
NUM_OUT_NODE = 100

# parse csv
# a. input node
reader = tf.TextLineReader()
key, value = reader.read(filename_inp)
deflist = [[0.] for idx in range(NUM_INP_NODE)]
input1 = tf.decode_csv(value, record_defaults=deflist)
# b. output node
key, value = reader.read(filename_out)
deflist = [[0.] for idx in range(NUM_OUT_NODE)]
output1 = tf.decode_csv(value, record_defaults=deflist)
# c. pack
inputs = tf.pack([input1])
outputs = tf.pack([output1])

batch_size = 4
inputs_batch, output_batch = tf.train.shuffle_batch([inputs, outputs], batch_size, capacity=40, min_after_dequeue = batch_size)

input_ph = tf.placeholder("float", [None, 1])
output_ph = tf.placeholder("float", [None, 1])

# network

PEP8でチェックしたら、以下のエラーが出た。

$ pep8 learn_in100out100.py
learn_in100out100.py:38:80: E501 line too long (127 > 79 characters)

改行してみた

inputs_batch, output_batch = tf.train.shuffle_batch([inputs, outputs], batch_size, capacity=40, min_after_dequeue = batch_size)

を以下のように改行した。

inputs_batch, output_batch = tf.train.shuffle_batch(
	[inputs, outputs], batch_size, capacity=40, min_after_dequeue = batch_size)

2行目はSublime Text2ではTabになった。

$ pep8 learn_in100out100.py
learn_in100out100.py:39:1: E101 indentation contains mixed spaces and tabs
learn_in100out100.py:39:1: W191 indentation contains tabs

Tabをやめた

Tabをやめて4つの空白にした。

inputs_batch, output_batch = tf.train.shuffle_batch(
    [inputs, outputs], batch_size, capacity=40, min_after_dequeue = batch_size)

$ pep8 learn_in100out100.py
learn_in100out100.py:39:66: E251 unexpected spaces around keyword / parameter equals
learn_in100out100.py:39:68: E251 unexpected spaces around keyword / parameter equals

改行する引数の位置を変更した

1つ目のリストでなく、2つ目のbatch_sizeから2行目にした。

inputs_batch, output_batch = tf.train.shuffle_batch([inputs, outputs], 
    batch_size, capacity=40, min_after_dequeue = batch_size)

$ pep8 learn_in100out100.py
learn_in100out100.py:39:5: E128 continuation line under-indented for visual indent

本題

learn_in100out100.py:39:5: E128 continuation line under-indented for visual indent

の対処。

参考 http://stackoverflow.com/questions/15435811/what-is-pep8s-e128-continuation-line-under-indented-for-visual-indent

引数の位置は括弧に合わせるとのこと。

inputs_batch, output_batch = tf.train.shuffle_batch([inputs, outputs],
                                                    batch_size, capacity=40, min_after_dequeue = batch_size)

$ pep8 learn_in100out100.py
learn_in100out100.py:39:80: E501 line too long (108 > 79 characters)
learn_in100out100.py:39:95: E251 unexpected spaces around keyword / parameter equals
learn_in100out100.py:39:97: E251 unexpected spaces around keyword / parameter equals

本題のエラーは解消されたが、1行が80文字以上になり、最初に戻る。

カーズは考えるのをやめた

4
3
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?