teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

インデントを修正しました。

2020/11/15 22:34

投稿

ot1982
ot1982

スコア6

title CHANGED
File without changes
body CHANGED
@@ -3,38 +3,39 @@
3
3
  その中でfor文をいくつか使っているところがあり、そのfor文の処理後の状態がどのようになっているかを確認したいです。作成したコードは、下記になります。
4
4
  ```
5
5
  import pandas as pd
6
+ import openpyxl as xl
6
7
  import os
7
8
 
8
- def make_pathlist(path): #pathlistを作成する
9
+ def make_pathlist(path):
9
- pathlist = [] #[]をpathlistに代入する
10
+ pathlist = []
10
- for curDir, dirs, files in os.walk(path): #指定したディレクトリからトップダウンの流れでディレクトリを走査
11
+ for curDir, dirs, files in os.walk(path): #指定したディレクトリからトップダウンの流れでディレクトリを走査
11
- dum = curDir.count('\') - org.count('\')
12
+ dum = curDir.count('\') - org.count('\') #ここでは何を変数に代入しているのか??
12
- for a_dir in dirs: #各ディレクトリの一覧を取得
13
+ for a_dir in dirs: #各ディレクトリの一覧を取得
13
- pathlist.append([curDir] + [''] * dum + [a_dir])
14
+ pathlist.append([curDir] + [''] * dum + [a_dir]) #ここでは何をしているのか??
14
- for a_file in files: #各ファイルの一覧を取得
15
+ for a_file in files: #各ファイルの一覧を取得
15
- pathlist.append([curDir] + [''] * dum + [a_file])
16
+ pathlist.append([curDir] + [''] * dum + [a_file]) #ここでは何をしているのか??
16
- mx = max(len(s) for s in pathlist)
17
+ mx = max(len(s) for s in pathlist) #ここでは何を変数に代入しているのか??
17
- return [s + [''] * (mx - len(s)) for s in pathlist]
18
+ return [s + [''] * (mx - len(s)) for s in pathlist] #何の戻り値を返しているのか?
18
19
 
19
- def conv_to_depthfirst(pathlist): #深さ優先順に変換
20
+ def conv_to_depthfirst(pathlist):
20
- for i in range(len(pathlist)): #0からpathlistの数を超えないを範囲で繰り返し処理をする
21
+ for i in range(len(pathlist)):
21
- for j in range(1, len(pathlist[i])):
22
+ for j in range(1, len(pathlist[i])):
22
- dir = os.path.join(pathlist[i][0], pathlist[i][j])
23
+ dir = os.path.join(pathlist[i][0], pathlist[i][j])
23
- if pathlist[i][j] and os.path.isdir(dir):
24
+ if pathlist[i][j] and os.path.isdir(dir):
24
- zs = ze = 0
25
+ zs = ze = 0
25
- for k in range(i+1, len(pathlist)):
26
+ for k in range(i+1, len(pathlist)):
26
- if pathlist[k][0].find(dir) >= 0:
27
+ if pathlist[k][0].find(dir) >= 0:
27
- if zs == 0:
28
+ if zs == 0:
28
- zs = ze = k
29
+ zs = ze = k
29
- else:
30
+ else:
30
- ze = k
31
+ ze = k
31
- else:
32
+ else:
32
- if zs > 0:
33
+ if zs > 0:
33
- break
34
+ break
34
- if zs > i + 1:
35
+ if zs > i + 1:
35
- # zs ~ ze を i と i + 1 の間に挿入する
36
+ # zs ~ ze を i と i + 1 の間に挿入する
36
- return conv_to_depthfirst(pathlist[0:i+1] + pathlist[zs:ze+1] + pathlist[i+1:zs] + pathlist[ze+1:])
37
+ return conv_to_depthfirst(pathlist[0:i+1] + pathlist[zs:ze+1] + pathlist[i+1:zs] + pathlist[ze+1:])
37
- return pathlist
38
+ return pathlist
39
+ ```
38
40
 
39
- 要するに、for文での処理が作業段階ごとにprintなどで出力して、ここでは何の作業をしているのだなと把握したいのですが、そのようなことってできるのでしょうか。
41
+ 要するに、for文での処理が作業段階ごとにprintなどで出力して、ここでは何の作業をしているのだなと把握したいのですが、そのようなことってできるのでしょうか。
40
- ```