回答編集履歴
4
Python2版を追記
test
CHANGED
@@ -34,4 +34,36 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
+
Python2 なら以下で。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```py
|
42
|
+
|
43
|
+
import datetime
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
tuple1 = (0,17,2,31,4)
|
48
|
+
|
49
|
+
tuple2 = (5,6,7,84,9)
|
50
|
+
|
51
|
+
tuple3 = (10,11,12,13,14)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
now = datetime.datetime.now()
|
56
|
+
|
57
|
+
filename = '/Usersfile/sample_' + now.strftime('%Y-%m-%d-%H-%M') + '.txt'
|
58
|
+
|
59
|
+
filename = 'sample_' + now.strftime('%Y-%m-%d-%H-%M') + '.txt'
|
60
|
+
|
61
|
+
|
62
|
+
|
37
|
-
p
|
63
|
+
with open(filename, "w") as f:
|
64
|
+
|
65
|
+
for line in zip(tuple1, tuple2, tuple3):
|
66
|
+
|
67
|
+
f.write(' '.join(map(str, line)) + '\n')
|
68
|
+
|
69
|
+
```
|
3
変数名変更
test
CHANGED
@@ -26,9 +26,9 @@
|
|
26
26
|
|
27
27
|
with open(filename, "w") as f:
|
28
28
|
|
29
|
-
for
|
29
|
+
for line in zip(tuple1, tuple2, tuple3):
|
30
30
|
|
31
|
-
print(*
|
31
|
+
print(*line, file=f)
|
32
32
|
|
33
33
|
```
|
34
34
|
|
2
ファイル出力処理追記
test
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
```py
|
6
|
+
|
7
|
+
import datetime
|
8
|
+
|
9
|
+
|
6
10
|
|
7
11
|
tuple1 = (0,17,2,31,4)
|
8
12
|
|
@@ -12,9 +16,19 @@
|
|
12
16
|
|
13
17
|
|
14
18
|
|
15
|
-
|
19
|
+
now = datetime.datetime.now()
|
16
20
|
|
21
|
+
|
22
|
+
|
23
|
+
filename = '/Usersfile/sample_' + now.strftime('%Y-%m-%d-%H-%M') + '.txt'
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
with open(filename, "w") as f:
|
28
|
+
|
29
|
+
for row in zip(tuple1, tuple2, tuple3):
|
30
|
+
|
17
|
-
print(*row)
|
31
|
+
print(*row, file=f)
|
18
32
|
|
19
33
|
```
|
20
34
|
|
1
説明変更
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
zip関数を使うといいです。
|
2
2
|
|
3
3
|
|
4
4
|
|