質問編集履歴
1
問題文修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Python3で書かれたコートの中で一部理解出来ない表現があります。
|
2
|
-
以下のコードは別ファイルから引数として渡された情報の中からid(ind_row)と選択肢(ind_row2/テキスト情報)の2種類のカラム情報を処理して
|
2
|
+
以下のコードは別ファイルから引数として渡された情報の中から遷移元id(ind_row)と選択肢(ind_row2/テキスト情報)の2種類のカラム情報を処理しています。
|
3
3
|
その中で以下の一部のコードについて自分の解釈が合っているか確認頂けたら幸いです。
|
4
4
|
単純なPythonの実力不足だとは思うのですが、少しでも理解して行きたくご質問させて頂きたいです。
|
5
5
|
|
@@ -30,9 +30,9 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
```
|
33
|
-
|
33
|
+
function.py
|
34
34
|
|
35
|
-
def _id_choice(fr,
|
35
|
+
def _id_choice(fr, ind_row, ind_row2):
|
36
36
|
len0 = 0
|
37
37
|
for row in fr:
|
38
38
|
if len0>0:
|
@@ -47,20 +47,41 @@
|
|
47
47
|
if len(b1)==1:
|
48
48
|
c = row_new1[0] ### choose one of choices! ###
|
49
49
|
c = c[:trunc] ### truncation! ###
|
50
|
-
f2.write("%s
|
50
|
+
f2.write("%s/%s\t%s\r\n" % (x,a,c)) # check later
|
51
51
|
else:
|
52
52
|
print("different numbers of items at ID: %s(%s)" % (row[0],name))
|
53
53
|
c = row_new1[b1.index(x)] # check later
|
54
54
|
c = c[:trunc] ### truncation! ###
|
55
|
-
f2.write("%s
|
55
|
+
f2.write("%s/%s\t%s\r\n" % (x,a,c)) # check later
|
56
56
|
else:
|
57
57
|
c = row_new1[b1.index(x)]
|
58
58
|
c = c[:trunc] ### truncation! ###
|
59
|
-
f2.write("%s
|
59
|
+
f2.write("%s/%s\t%s\r\n" % (x,a,c))
|
60
60
|
else:
|
61
61
|
c = row_new1[0]
|
62
62
|
c = c[:trunc] ### truncation! ###
|
63
|
-
f2.write("%s
|
63
|
+
f2.write("%s/%s\t%s\r\n" % (x,a,c))
|
64
64
|
len0 += 1
|
65
65
|
return len0
|
66
|
+
```
|
67
|
+
```
|
68
|
+
deal_csv.py
|
69
|
+
|
70
|
+
if switch == 1:
|
71
|
+
f0, fr0 = _load_file(file0)
|
72
|
+
file2 = "./id_choice.tsv"
|
73
|
+
f2 = codecs.open(file2, "w", "utf-8")
|
74
|
+
f2.write("%s\t%s\r\n" % ("ID_bef/aft","choice"))
|
75
|
+
trunc = 100 # trancation length
|
76
|
+
len2 = _id_choice(fr0,2,3) # depends on csv file
|
77
|
+
f0.close()
|
78
|
+
f2.close()
|
79
|
+
|
80
|
+
```
|
81
|
+
```
|
82
|
+
csvファイルカラム構造
|
83
|
+
|
84
|
+
id|message|遷移元id|選択肢|
|
85
|
+
1 xxxxxx 30/31/32 選択肢1
|
86
|
+
2 xxxxxx 40/41/42 選択肢2
|
66
87
|
```
|