0
0

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 1 year has passed since last update.

autopep8で特定ブロックの自動整形を除外する

Posted at

結論

autopep8: off/onでくくる

#autopep8: off
なんらかの処理
#autopep8: on

元のコード

# タイトルを別に作成する
title_row = [tk.Label(frame, text="#")
       ,tk.Checkbutton(frame, variable=tk.BooleanVar(value=False))
       ,tk.Label(frame, text=_("title"))
       ,tk.Label(frame, text=_("file name"))
       ,tk.Label(frame, text=_("file size"))
       ,tk.Label(frame, text=_("album artist"))
       ,tk.Label(frame, text=_("album title"))
       ,tk.Label(frame, text=_("artist"))
       ,tk.Label(frame, text=_("directory"))
       ]

# 中身の作成
rows = [[
        tk.Label(frame, text=str(i+1))
        ,tk.Checkbutton(frame, variable=list[i+1].need_export)
        ,tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].title))
        ,tk.Label(frame, text=list[i+1].value[int(music.col.FILE_NAME)])
        ,tk.Label(frame, text=list[i+1].value[int(music.col.FILE_SIZE)])
        ,tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].album_artist))
        ,tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].album))
        ,tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].artist))
        ,tk.Label(frame, text=list[i+1].value[int(music.col.DIRECTORY)])
    ] for i in range(len(list) - 1)]
rows.insert(0, title_row)

普通にautopep8をかけると

長すぎやろ

# タイトルを別に作成する
title_row = [tk.Label(frame, text="#"), tk.Checkbutton(frame, variable=tk.BooleanVar(value=False)), tk.Label(frame, text=_("title")), tk.Label(frame, text=_("file name")), tk.Label(frame, text=_("file size")), tk.Label(frame, text=_("album artist")), tk.Label(frame, text=_("album title")), tk.Label(frame, text=_("artist")), tk.Label(frame, text=_("directory"))
             ]

# 中身の作成
rows = [[
        tk.Label(frame, text=str(i+1)), tk.Checkbutton(frame, variable=list[i+1].need_export), tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].title)), tk.Label(frame, text=list[i+1].value[int(music.col.FILE_NAME)]), tk.Label(frame, text=list[i+1].value[int(music.col.FILE_SIZE)]), tk.Entry(
            frame, textvariable=tk.StringVar(value=list[i+1].album_artist)), tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].album)), tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].artist)), tk.Label(frame, text=list[i+1].value[int(music.col.DIRECTORY)])
        ] for i in range(len(list) - 1)]
rows.insert(0, title_row)

aggressive1回

ないわー

# タイトルを別に作成する
title_row = [tk.Label(frame, text="#"), tk.Checkbutton(frame, variable=tk.BooleanVar(value=False)), tk.Label(frame, text=_("title")), tk.Label(frame, text=_("file name")), tk.Label(frame, text=_("file size")), tk.Label(frame, text=_("album artist")), tk.Label(frame, text=_("album title")), tk.Label(frame, text=_("artist")), tk.Label(frame, text=_("directory"))
             ]

# 中身の作成
rows = [[
        tk.Label(frame, text=str(i +
                                 1)), tk.Checkbutton(frame, variable=list[i +
                                                                          1].need_export), tk.Entry(frame, textvariable=tk.StringVar(value=list[i +
                                                                                                                                                1].title)), tk.Label(frame, text=list[i +
                                                                                                                                                                                      1].value[int(music.col.FILE_NAME)]), tk.Label(frame, text=list[i +
                                                                                                                                                                                                                                                     1].value[int(music.col.FILE_SIZE)]), tk.Entry(frame, textvariable=tk.StringVar(value=list[i +
                                                                                                                                                                                                                                                                                                                                               1].album_artist)), tk.Entry(frame, textvariable=tk.StringVar(value=list[i +
                                                                                                                                                                                                                                                                                                                                                                                                                       1].album)), tk.Entry(frame, textvariable=tk.StringVar(value=list[i +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1].artist)), tk.Label(frame, text=list[i +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               1].value[int(music.col.DIRECTORY)])
        ] for i in range(len(list) - 1)]
rows.insert(0, title_row)

aggressive2回

あかんやろ

# タイトルを別に作成する
title_row = [
    tk.Label(
        frame, text="#"), tk.Checkbutton(
        frame, variable=tk.BooleanVar(
            value=False)), tk.Label(
            frame, text=_("title")), tk.Label(
                frame, text=_("file name")), tk.Label(
                    frame, text=_("file size")), tk.Label(
                        frame, text=_("album artist")), tk.Label(
                            frame, text=_("album title")), tk.Label(
                                frame, text=_("artist")), tk.Label(
                                    frame, text=_("directory"))]

# 中身の作成
rows = [[tk.Label(frame, text=str(i +
                                  1)), tk.Checkbutton(frame, variable=list[i +
                                                                           1].need_export), tk.Entry(frame, textvariable=tk.StringVar(value=list[i +
                                                                                                                                                 1].title)), tk.Label(frame, text=list[i +
                                                                                                                                                                                       1].value[int(music.col.FILE_NAME)]), tk.Label(frame, text=list[i +
                                                                                                                                                                                                                                                      1].value[int(music.col.FILE_SIZE)]), tk.Entry(frame, textvariable=tk.StringVar(value=list[i +
                                                                                                                                                                                                                                                                                                                                                1].album_artist)), tk.Entry(frame, textvariable=tk.StringVar(value=list[i +
                                                                                                                                                                                                                                                                                                                                                                                                                        1].album)), tk.Entry(frame, textvariable=tk.StringVar(value=list[i +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         1].artist)), tk.Label(frame, text=list[i +
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1].value[int(music.col.DIRECTORY)])] for i in range(len(list) -
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1)]
rows.insert(0, title_row)

コマンド入れて通常モードでかけると

見逃してくれた

#autopep8: off
# タイトルを別に作成する
title_row = [tk.Label(frame, text="#")
       ,tk.Checkbutton(frame, variable=tk.BooleanVar(value=False))
       ,tk.Label(frame, text=_("title"))
       ,tk.Label(frame, text=_("file name"))
       ,tk.Label(frame, text=_("file size"))
       ,tk.Label(frame, text=_("album artist"))
       ,tk.Label(frame, text=_("album title"))
       ,tk.Label(frame, text=_("artist"))
       ,tk.Label(frame, text=_("directory"))
       ]

# 中身の作成
rows = [[
        tk.Label(frame, text=str(i+1))
        ,tk.Checkbutton(frame, variable=list[i+1].need_export)
        ,tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].title))
        ,tk.Label(frame, text=list[i+1].value[int(music.col.FILE_NAME)])
        ,tk.Label(frame, text=list[i+1].value[int(music.col.FILE_SIZE)])
        ,tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].album_artist))
        ,tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].album))
        ,tk.Entry(frame, textvariable=tk.StringVar(value=list[i+1].artist))
        ,tk.Label(frame, text=list[i+1].value[int(music.col.DIRECTORY)])
    ] for i in range(len(list) - 1)]
#autopep8: on
rows.insert(0, title_row)
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?