質問編集履歴
2
ちょっとかえた
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
```python
|
5
5
|
import time
|
6
6
|
with open("file.csv", "a") as f:
|
7
|
-
|
7
|
+
while True:
|
8
8
|
f.write("hello\n")
|
9
9
|
time.sleep(3)
|
10
10
|
```
|
@@ -13,9 +13,9 @@
|
|
13
13
|
|
14
14
|
```python
|
15
15
|
while True:
|
16
|
-
with open("file.csv", "a") as f:
|
16
|
+
with open("file.csv", "a") as f:
|
17
|
-
|
17
|
+
f.write("hello\n")
|
18
|
-
|
18
|
+
time.sleep(3)
|
19
19
|
```
|
20
20
|
|
21
21
|
として書き込む度にopenしないといけないのでしょうか
|
1
インデント
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
openでファイルを書き込み専用で開いた後、while Trueで無限ループで書き込みを行いたいのですが、プログラムが正常に終了しないと反映されないのでしょうか?
|
2
2
|
|
3
3
|
・書いたコード
|
4
|
+
```python
|
4
5
|
import time
|
5
6
|
with open("file.csv", "a") as f:
|
6
7
|
while True:
|
7
8
|
f.write("hello\n")
|
8
9
|
time.sleep(3)
|
10
|
+
```
|
9
11
|
|
10
12
|
任意のタイミングでプログラムを停止してもfile.csvには何もかきこまれていませんでした。
|
11
13
|
|
12
|
-
|
14
|
+
```python
|
13
15
|
while True:
|
14
16
|
with open("file.csv", "a") as f:
|
15
17
|
f.write("hello\n")
|
16
18
|
time.sleep(3)
|
19
|
+
```
|
17
20
|
|
18
|
-
として書き込む度にopenしないといけないのでしょうか
|
21
|
+
として書き込む度にopenしないといけないのでしょうか
|
22
|
+
|
23
|
+
osはwindows10
|
24
|
+
pycharmで実行・停止しています
|